aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/user_controller.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-11-01 23:44:58 +0000
committerFrancis Irving <francis@mysociety.org>2009-11-01 23:44:58 +0000
commit81fa07c4baa3f3ff01cdb5181d0870f20340cd5b (patch)
tree813239b211fc4457d89011187194a358879b8673 /app/controllers/user_controller.rb
parent8cd53c254afd8c65adb81d44b1509adc764406ad (diff)
Part of profile photo
Diffstat (limited to 'app/controllers/user_controller.rb')
-rw-r--r--app/controllers/user_controller.rb41
1 files changed, 36 insertions, 5 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 01601bce6..33728b65e 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -107,7 +107,7 @@ class UserController < ApplicationController
# Make the user and try to save it
@user_signup = User.new(params[:user_signup])
- if not @user_signup.valid?
+ if !@user_signup.valid?
# Show the form
render :action => 'sign'
else
@@ -325,10 +325,41 @@ class UserController < ApplicationController
render :action => 'confirm' # must be same as for send_confirmation_mail above to avoid leak of presence of email in db
end
- def set_profile_photo
- @photo_user = User.find(params[:id])
- new_profile_photo = ProfilePhoto.new(:data => data)
- @photo_user.set_profile_photo(new_profile_photo)
+ def profile_photo
+ raise 'boo"
+ # check they are logged in (the upload photo option is anyway only available when logged in)
+ if authenticated_user.nil?
+ flash[:error] = "You need to be logged in to change your profile photo."
+ redirect_to frontpage_url
+ return
+ end
+ if params[:submitted_profile_photo].nil?
+ # default page
+ return
+ end
+
+ # check for uploaded image
+ file_name = nil
+ file_content = nil
+ if params[:file].class.to_s == "ActionController::UploadedTempfile"
+ file_name = params[:file].original_filename
+ file_content = params[:file].read
+ end
+ if file_name.nil?
+ flash[:error] = "Please type a message and/or choose a file containing your response."
+ return
+ end
+
+ # change user's photo
+ new_profile_photo = ProfilePhoto.new(:data => params[:data])
+ if !new_profile_photo.valid?
+ # error page
+ return
+ end
+ @user.set_profile_photo(new_profile_photo)
+
+ flash[:notice] = "Thank you for updating your profile photo"
+ redirect_to user_url(@user)
end
end