Sha256: d098f1744154f25292c50a0a2cbfc9143580e6096a23286ce6c0c121f427e2b3

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 KB

Contents

module Clearance
  # Runs as the base {SignInGuard} for all requests, regardless of configured
  # {Configuration#sign_in_guards}.
  class DefaultSignInGuard < SignInGuard
    # 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}.
    #
    # @return [SuccessStatus, FailureStatus]
    def call
      if session.signed_in?
        success
      else
        failure default_failure_message.html_safe
      end
    end

    # 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`
    #
    # @return [String]
    def default_failure_message
      I18n.t(
        :bad_email_or_password,
        scope: [:clearance, :controllers, :sessions],
        default: I18n.t('flashes.failure_after_create').html_safe
      )
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
clearance-2.9.2 lib/clearance/default_sign_in_guard.rb
clearance-2.9.1 lib/clearance/default_sign_in_guard.rb
clearance-2.9.0 lib/clearance/default_sign_in_guard.rb
clearance-2.8.0 lib/clearance/default_sign_in_guard.rb
clearance-2.7.2 lib/clearance/default_sign_in_guard.rb
clearance-2.7.0 lib/clearance/default_sign_in_guard.rb
clearance-2.6.2 lib/clearance/default_sign_in_guard.rb
clearance-2.6.1 lib/clearance/default_sign_in_guard.rb
clearance-2.6.0 lib/clearance/default_sign_in_guard.rb
clearance-2.5.0 lib/clearance/default_sign_in_guard.rb
clearance-2.4.0 lib/clearance/default_sign_in_guard.rb
clearance-2.3.1 lib/clearance/default_sign_in_guard.rb
clearance-2.3.0 lib/clearance/default_sign_in_guard.rb
clearance-2.2.1 lib/clearance/default_sign_in_guard.rb
clearance-2.2.0 lib/clearance/default_sign_in_guard.rb
clearance-2.1.0 lib/clearance/default_sign_in_guard.rb
clearance-2.0.0 lib/clearance/default_sign_in_guard.rb
clearance-2.0.0.beta2 lib/clearance/default_sign_in_guard.rb
clearance-2.0.0.beta1 lib/clearance/default_sign_in_guard.rb
clearance-1.17.0 lib/clearance/default_sign_in_guard.rb