Class: Clearance::DefaultSignInGuard

Inherits:
SignInGuard show all
Defined in:
lib/clearance/default_sign_in_guard.rb

Overview

Runs as the base SignInGuard for all requests, regardless of configured Configuration#sign_in_guards.

Instance Attribute Summary

Attributes inherited from SignInGuard

#session, #stack

Instance Method Summary collapse

Methods inherited from SignInGuard

#current_user, #failure, #initialize, #next_guard, #signed_in?, #success

Constructor Details

This class inherits a constructor from Clearance::SignInGuard

Instance Method Details

#callSuccessStatus, FailureStatus

Runs the default sign in guard.

If there is a value set in the clearance session object, then the guard returns SuccessStatus. Otherwise, it returns FailureStatus with the message returned by #default_failure_message.



12
13
14
15
16
17
18
# File 'lib/clearance/default_sign_in_guard.rb', line 12

def call
  if session.signed_in?
    success
  else
    failure default_failure_message.html_safe
  end
end

#default_failure_messageString

The default failure message pulled from the i18n framework.

Will use the value returned from the following i18n keys, in this order:

  • clearance.controllers.sessions.bad_email_or_password
  • flashes.failure_after_create

Returns:

  • (String)


28
29
30
31
32
33
34
# File 'lib/clearance/default_sign_in_guard.rb', line 28

def default_failure_message
  I18n.t(
    :bad_email_or_password,
    scope: [:clearance, :controllers, :sessions],
    default: I18n.t('flashes.failure_after_create').html_safe
  )
end