Sha256: f9b4b37ee8aaf40df97d5673777b3f8b24d1b8a2ba2234610f98e12ae9384205

Contents?: true

Size: 979 Bytes

Versions: 6

Compression:

Stored size: 979 Bytes

Contents

class Clearance::SessionsController < Clearance::BaseController
  before_action :redirect_signed_in_users, only: [:new]
  skip_before_action :require_login, only: [:create, :new, :destroy], raise: false

  def create
    @user = authenticate(params)

    sign_in(@user) do |status|
      if status.success?
        redirect_back_or url_after_create
      else
        flash.now.alert = status.failure_message
        render template: "sessions/new", status: :unauthorized
      end
    end
  end

  def destroy
    sign_out
    redirect_to url_after_destroy, status: :see_other
  end

  def new
    render template: "sessions/new"
  end

  private

  def redirect_signed_in_users
    if signed_in?
      redirect_to url_for_signed_in_users
    end
  end

  def url_after_create
    Clearance.configuration.redirect_url
  end

  def url_after_destroy
    Clearance.configuration.url_after_destroy || sign_in_url
  end

  def url_for_signed_in_users
    url_after_create
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
clearance-2.9.2 app/controllers/clearance/sessions_controller.rb
clearance-2.9.1 app/controllers/clearance/sessions_controller.rb
clearance-2.9.0 app/controllers/clearance/sessions_controller.rb
clearance-2.8.0 app/controllers/clearance/sessions_controller.rb
clearance-2.7.2 app/controllers/clearance/sessions_controller.rb
clearance-2.7.0 app/controllers/clearance/sessions_controller.rb