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 "    def ensure_mandatory_\#{mapping}_otp!\n      resource = current_\#{mapping}\n      if !devise_controller?\n        if mandatory_otp_missing_on?(resource)\n          redirect_to edit_\#{mapping}_otp_token_path\n        end\n      end\n    end\n  METHODS\nend\n", __FILE__, __LINE__ + 1

.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:



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:



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