diff options
Diffstat (limited to 'app/controllers/user_controller.rb')
-rw-r--r-- | app/controllers/user_controller.rb | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 77508e0c6..b3f9511b5 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 @@ -342,6 +342,42 @@ class UserController < ApplicationController }.flatten.sort { |a,b| b[:model].created_at <=> a[:model].created_at }.first(20) end + def profile_photo + # 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].nil? + file_name = params[:file].original_filename + file_content = params[:file].read + end + if file_name.nil? + flash[:error] = "Please choose a file containing your photo" + return + end + + # change user's photo + @profile_photo = ProfilePhoto.new(:data => file_content) + @user.set_profile_photo(@profile_photo) + if !@profile_photo.valid? + # error page (uses @profile_photo's error fields in view to show errors) + return + end + + flash[:notice] = "Thank you for updating your profile photo" + redirect_to user_url(@user) + end + private # Decide where we are going to redirect back to after signin/signup, and record that @@ -388,10 +424,5 @@ 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) - end end |