Sha256: fdbec61a0d936be2a4c5a05a4314962afce34895438c18f8a1ab220693d6a3e8

Contents?: true

Size: 1.66 KB

Versions: 9

Compression:

Stored size: 1.66 KB

Contents

class Clearance::SessionsController < ApplicationController
  unloadable

  protect_from_forgery :except => :create
  filter_parameter_logging :password

  def new
    render :template => 'sessions/new'
  end

  def create
    @user = ::User.authenticate(params[:session][:email],
                                params[:session][:password])
    if @user.nil?
      flash_failure_after_create
      render :template => 'sessions/new', :status => :unauthorized
    else
      if @user.email_confirmed?
        sign_in(@user)
        remember(@user) if remember?
        flash_success_after_create
        redirect_back_or(url_after_create)
      else
        ::ClearanceMailer.deliver_confirmation(@user)
        flash_notice_after_create
        redirect_to(new_session_url)
      end
    end
  end

  def destroy
    forget(current_user)
    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
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
thoughtbot-clearance-0.6.7 app/controllers/clearance/sessions_controller.rb
thoughtbot-clearance-0.6.8 app/controllers/clearance/sessions_controller.rb
thoughtbot-clearance-0.6.9 app/controllers/clearance/sessions_controller.rb
thoughtbot-clearance-0.7.0 app/controllers/clearance/sessions_controller.rb
tonkapark-clearance-0.6.9.1 app/controllers/clearance/sessions_controller.rb
tonkapark-clearance-0.7.0 app/controllers/clearance/sessions_controller.rb
vita-clearance-0.6.9.1 app/controllers/clearance/sessions_controller.rb
vita-clearance-0.6.9.2 app/controllers/clearance/sessions_controller.rb
vita-clearance-0.6.9 app/controllers/clearance/sessions_controller.rb