Sha256: b9ac46730e6a93da5576401d7fad4eaec67aa6a1a4b9c1e7018286f55272eb18

Contents?: true

Size: 1.72 KB

Versions: 20

Compression:

Stored size: 1.72 KB

Contents

class Clearance::SessionsController < ApplicationController
  unloadable

  skip_before_filter :authenticate, :only => [:new, :create, :destroy]
  protect_from_forgery :except => :create
  filter_parameter_logging :password

  def new
    if !signed_in? then render :template => 'sessions/new'
    else redirect_back_or(url_after_create) end
  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)
        flash_success_after_create
        redirect_back_or(url_after_create)
      else
        ::ClearanceMailer.deliver_confirmation(@user)
        flash_notice_after_create
        redirect_to(sign_in_url)
      end
    end
  end

  def destroy
    sign_out
    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
    URL_AFTER_CREATE
  end

  def flash_success_after_destroy
    flash[:success] = translate(:signed_out, :default =>  "Signed out.")
  end

  def url_after_destroy
    sign_in_url
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fbdoorman-0.7.9.1 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.9 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.8 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.7 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.6 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.4 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.3 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.2 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.1 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.7.0 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.1.0 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.9 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.8 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.7 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.6 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.5 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.4 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.3 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.2 app/controllers/clearance/sessions_controller.rb
fbdoorman-0.0.1 app/controllers/clearance/sessions_controller.rb