@@ -40,12 +40,12 @@ class User < ApplicationRecord
40
40
has_many :sessions , dependent : :destroy
41
41
has_many :posts , dependent : :destroy
42
42
43
- before_validation :process_otp_action
44
-
45
43
validates :email , presence : true , email : true , uniqueness : true
46
44
validates :name , presence : true
47
45
validates :password , format : { with : PASSWORD_FORMAT } , allow_blank : true
48
46
47
+ before_validation :process_otp_action
48
+
49
49
def save_password_reset_token
50
50
generate_unique_token ( :password_reset_token )
51
51
self . password_reset_sent_at = Time . zone . now
@@ -60,17 +60,6 @@ def otp_action=(input)
60
60
@otp_action = input . to_h
61
61
end
62
62
63
- def process_otp_action
64
- # otp_action = nil OR {} OR {enable:, code:}
65
- return if @otp_action . blank?
66
-
67
- if @otp_action [ :enable ]
68
- enable_otp
69
- else
70
- disable_otp
71
- end
72
- end
73
-
74
63
def enable_otp
75
64
code = @otp_action [ :code ]
76
65
if authenticate_otp ( code , drift : 60 )
@@ -89,4 +78,17 @@ def disable_otp
89
78
errors . add ( :otp_code )
90
79
end
91
80
end
81
+
82
+ private
83
+
84
+ def process_otp_action
85
+ # otp_action = nil OR {} OR {enable:, code:}
86
+ return if @otp_action . blank?
87
+
88
+ if @otp_action [ :enable ]
89
+ enable_otp
90
+ else
91
+ disable_otp
92
+ end
93
+ end
92
94
end
0 commit comments