Module: Devise::Models::ParanoidVerification

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise-security/models/paranoid_verification.rb

Overview

PasswordExpirable takes care of change password after

Instance Method Summary collapse

Instance Method Details

#generate_paranoid_codeObject


34
35
36
37
# File 'lib/devise-security/models/paranoid_verification.rb', line 34

def generate_paranoid_code
  update_without_password paranoid_verification_code: Devise.verification_code_generator.call(),
                          paranoid_verification_attempt: 0
end

#need_paranoid_verification?Boolean

Returns:

  • (Boolean)

11
12
13
# File 'lib/devise-security/models/paranoid_verification.rb', line 11

def need_paranoid_verification?
  !!paranoid_verification_code
end

#paranoid_attempts_remainingObject


30
31
32
# File 'lib/devise-security/models/paranoid_verification.rb', line 30

def paranoid_attempts_remaining
  Devise.paranoid_code_regenerate_after_attempt - paranoid_verification_attempt
end

#verify_code(code) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/devise-security/models/paranoid_verification.rb', line 15

def verify_code(code)
  attempt = paranoid_verification_attempt

  if (attempt += 1) >= Devise.paranoid_code_regenerate_after_attempt
    generate_paranoid_code
  elsif code == paranoid_verification_code
    attempt = 0
    update_without_password paranoid_verification_code: nil,
                            paranoid_verified_at: Time.now,
                            paranoid_verification_attempt: attempt
  else
    update_without_password paranoid_verification_attempt: attempt
  end
end