]> git.openstreetmap.org Git - rails.git/blob - app/controllers/concerns/user_methods.rb
Localisation updates from https://translatewiki.net.
[rails.git] / app / controllers / concerns / user_methods.rb
1 module UserMethods
2   extend ActiveSupport::Concern
3
4   private
5
6   ##
7   # update a user's details
8   def update_user(user, params)
9     user.display_name = params[:display_name]
10     user.new_email = params[:new_email]
11
12     unless params[:pass_crypt].empty? && params[:pass_crypt_confirmation].empty?
13       user.pass_crypt = params[:pass_crypt]
14       user.pass_crypt_confirmation = params[:pass_crypt_confirmation]
15     end
16
17     if params[:auth_provider].nil? || params[:auth_provider].blank?
18       user.auth_provider = nil
19       user.auth_uid = nil
20     end
21
22     if user.save
23       session[:fingerprint] = user.fingerprint
24
25       if user.new_email.blank? || user.new_email == user.email
26         flash[:notice] = t "accounts.update.success"
27       else
28         user.email = user.new_email
29
30         if user.valid?
31           flash[:notice] = t "accounts.update.success_confirm_needed"
32
33           begin
34             UserMailer.email_confirm(user, user.tokens.create).deliver_later
35           rescue StandardError
36             # Ignore errors sending email
37           end
38         else
39           current_user.errors.add(:new_email, current_user.errors[:email])
40           current_user.errors.add(:email, [])
41         end
42
43         user.restore_email!
44       end
45     end
46   end
47 end