Module: DeviseOtpAuthenticatable::Controllers::PublicHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise_otp_authenticatable/controllers/public_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_helpers(mapping) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/devise_otp_authenticatable/controllers/public_helpers.rb', line 12

def self.define_helpers(mapping) #:nodoc:
  mapping = mapping.name

  class_eval <<-METHODS, __FILE__, __LINE__ + 1
    def ensure_mandatory_#{mapping}_otp!
      resource = current_#{mapping}
      if !devise_controller?
        if mandatory_otp_missing_on?(resource)
          redirect_to edit_#{mapping}_otp_token_path
        end
      end
    end
  METHODS
end

.generate_helpers!Object



6
7
8
9
10
# File 'lib/devise_otp_authenticatable/controllers/public_helpers.rb', line 6

def self.generate_helpers!
  Devise.mappings.each do |key, mapping|
    self.define_helpers(mapping)
  end
end

Instance Method Details

#mandatory_otp_missing_on?(resource) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/devise_otp_authenticatable/controllers/public_helpers.rb', line 33

def mandatory_otp_missing_on?(resource)
  otp_mandatory_on?(resource) && !resource.otp_enabled
end

#otp_mandatory_on?(resource) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/devise_otp_authenticatable/controllers/public_helpers.rb', line 27

def otp_mandatory_on?(resource)
  return false unless resource.respond_to?(:otp_mandatory)

  resource.class.otp_mandatory or resource.otp_mandatory
end