2 extend ActiveSupport::Concern
7 # ensure that there is a "user" instance variable
9 display_name = params[:display_name] || params[:user_display_name]
10 @user = User.active.find_by!(:display_name => display_name)
11 rescue ActiveRecord::RecordNotFound
12 render_unknown_user display_name
16 # render a "no such user" page
17 def render_unknown_user(name)
18 @title = t "users.no_such_user.title"
19 @not_found_user = name
21 respond_to do |format|
22 format.html { render :template => "users/no_such_user", :status => :not_found, :layout => "site" }
23 format.all { head :not_found }
28 # update a user's details
29 def update_user(user, params)
30 user.display_name = params[:display_name]
31 user.new_email = params[:new_email]
33 unless params[:pass_crypt].empty? && params[:pass_crypt_confirmation].empty?
34 user.pass_crypt = params[:pass_crypt]
35 user.pass_crypt_confirmation = params[:pass_crypt_confirmation]
38 if params[:auth_provider].nil? || params[:auth_provider].blank?
39 user.auth_provider = nil
44 session[:fingerprint] = user.fingerprint
46 if user.new_email.blank? || user.new_email == user.email
47 flash[:notice] = t "accounts.update.success"
49 token = user.generate_token_for(:new_email)
51 user.email = user.new_email
54 flash[:notice] = t "accounts.update.success_confirm_needed"
57 UserMailer.email_confirm(user, token).deliver_later
59 # Ignore errors sending email
62 current_user.errors.add(:new_email, current_user.errors[:email])
63 current_user.errors.add(:email, [])