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, :layout => "site" }
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 token = user.generate_token_for(:new_email)
50 user.email = user.new_email
53 flash[:notice] = t "accounts.update.success_confirm_needed"
56 UserMailer.email_confirm(user, token).deliver_later
58 # Ignore errors sending email
61 current_user.errors.add(:new_email, current_user.errors[:email])
62 current_user.errors.add(:email, [])