app/controllers/clearance/sessions_controller.rb in thoughtbot-clearance-0.6.6 vs app/controllers/clearance/sessions_controller.rb in thoughtbot-clearance-0.6.7

- old
+ new

@@ -8,41 +8,58 @@ render :template => 'sessions/new' end def create @user = ::User.authenticate(params[:session][:email], - params[:session][:password]) + params[:session][:password]) if @user.nil? - flash.now[:failure] = translate(:bad_email_or_password, - :scope => [:clearance, :controllers, :sessions], - :default => "Bad email or password.") + flash_failure_after_create render :template => 'sessions/new', :status => :unauthorized else if @user.email_confirmed? - sign_user_in(@user) + sign_in(@user) remember(@user) if remember? - flash[:success] = translate(:signed_in, :default => "Signed in.") - redirect_back_or url_after_create + flash_success_after_create + redirect_back_or(url_after_create) else ::ClearanceMailer.deliver_confirmation(@user) - deny_access(translate(:unconfirmed_email, - :scope => [:clearance, :controllers, :sessions], - :default => "User has not confirmed email. " << - "Confirmation email will be resent.")) + flash_notice_after_create + redirect_to(new_session_url) end end end def destroy forget(current_user) - flash[:success] = translate(:signed_out, :default => "Signed out.") - redirect_to url_after_destroy + flash_success_after_destroy + redirect_to(url_after_destroy) end private + def flash_failure_after_create + flash.now[:failure] = translate(:bad_email_or_password, + :scope => [:clearance, :controllers, :sessions], + :default => "Bad email or password.") + end + + def flash_success_after_create + flash[:success] = translate(:signed_in, :default => "Signed in.") + end + + def flash_notice_after_create + flash[:notice] = translate(:unconfirmed_email, + :scope => [:clearance, :controllers, :sessions], + :default => "User has not confirmed email. " << + "Confirmation email will be resent.") + end + def url_after_create root_url + end + + def flash_success_after_destroy + flash[:success] = translate(:signed_out, :default => "Signed out.") end def url_after_destroy new_session_url end