2 extend ActiveSupport::Concern
7 # ensure that there is a "user" instance variable
9 @user = User.active.find_by!(:display_name => params[:display_name])
10 rescue ActiveRecord::RecordNotFound
11 render_unknown_user params[:display_name]
15 # render a "no such user" page
16 def render_unknown_user(name)
17 @title = t "users.no_such_user.title"
18 @not_found_user = name
20 respond_to do |format|
21 format.html { render :template => "users/no_such_user", :status => :not_found }
22 format.all { head :not_found }
27 # update a user's details
28 def update_user(user, params)
29 user.display_name = params[:display_name]
30 user.new_email = params[:new_email]
32 unless params[:pass_crypt].empty? && params[:pass_crypt_confirmation].empty?
33 user.pass_crypt = params[:pass_crypt]
34 user.pass_crypt_confirmation = params[:pass_crypt_confirmation]
37 if params[:auth_provider].nil? || params[:auth_provider].blank?
38 user.auth_provider = nil
43 session[:fingerprint] = user.fingerprint
45 if user.new_email.blank? || user.new_email == user.email
46 flash[:notice] = t "accounts.update.success"
48 user.email = user.new_email
51 flash[:notice] = t "accounts.update.success_confirm_needed"
54 UserMailer.email_confirm(user, user.tokens.create).deliver_later
56 # Ignore errors sending email
59 current_user.errors.add(:new_email, current_user.errors[:email])
60 current_user.errors.add(:email, [])