10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/generators/authentication/templates/controllers/concerns/two_factor_authentication.rb', line 10
def define_tfa_methods(model_name)
define_method :"authenticate_#{model_name}_with_tfa" do
send(:"authenticate_#{model_name}_without_tfa")
record = send(:"current_#{model_name}")
return unless record
if record.tfa? && !send(:"current_#{model_name}_tfa_authenticated?")
redirect_to send(:"new_#{model_name.to_s.pluralize}_tfa_session_url"),
warn: "You cannot proceed without authenticating"
end
end
define_method :"current_#{model_name}_tfa_authenticated?" do
session[:"#{model_name}_tfa_authenticated"] == true
end
define_method :"#{model_name}_tfa_success_redirect_url" do
send(:"#{model_name.to_s.pluralize}_dashboard_url")
end
alias_method :"authenticate_#{model_name}_without_tfa", :"authenticate_#{model_name}"
alias_method :"authenticate_#{model_name}", :"authenticate_#{model_name}_with_tfa"
end
|