Class: Redmine::Twofa::Totp
- Inherits:
-
Base
- Object
- Base
- Redmine::Twofa::Totp
show all
- Defined in:
- lib/redmine/twofa/totp.rb
Instance Method Summary
collapse
Methods inherited from Base
#backup_codes, #confirm_pairing!, #deliver_twofa_paired, #deliver_twofa_unpaired, #destroy_pairing!, inherited, #init_backup_codes!, #initialize, #otp_confirm_view_variables, scheme_name, #scheme_name, #send_code, #verify!, #verify_backup_code!
Instance Method Details
#destroy_pairing_without_verify! ⇒ Object
32
33
34
35
36
37
|
# File 'lib/redmine/twofa/totp.rb', line 32
def destroy_pairing_without_verify!
@user.update!(twofa_totp_key: nil, twofa_totp_last_used_at: nil)
@totp = nil
super
end
|
#init_pairing! ⇒ Object
25
26
27
28
29
30
|
# File 'lib/redmine/twofa/totp.rb', line 25
def init_pairing!
@user.update!(twofa_totp_key: ROTP::Base32.random)
@totp = nil
super
end
|
#init_pairing_view_variables ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/redmine/twofa/totp.rb', line 56
def init_pairing_view_variables
super.merge(
{
provisioning_uri: provisioning_uri,
totp_key: @user.twofa_totp_key
}
)
end
|
#provisioning_uri ⇒ Object
52
53
54
|
# File 'lib/redmine/twofa/totp.rb', line 52
def provisioning_uri
totp.provisioning_uri(@user.login)
end
|
#verify_otp!(code) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/redmine/twofa/totp.rb', line 39
def verify_otp!(code)
code = code.to_s.remove(/[[:space:]]/)
last_verified_at = @user.twofa_totp_last_used_at
verified_at = totp.verify(code.to_s, drift_behind: allowed_drift, after: last_verified_at)
if verified_at
@user.update!(twofa_totp_last_used_at: verified_at)
true
else
false
end
end
|