@@ -40,12 +40,12 @@ class User < ApplicationRecord
4040 has_many :sessions , dependent : :destroy
4141 has_many :posts , dependent : :destroy
4242
43- before_validation :process_otp_action
44-
4543 validates :email , presence : true , email : true , uniqueness : true
4644 validates :name , presence : true
4745 validates :password , format : { with : PASSWORD_FORMAT } , allow_blank : true
4846
47+ before_validation :process_otp_action
48+
4949 def save_password_reset_token
5050 generate_unique_token ( :password_reset_token )
5151 self . password_reset_sent_at = Time . zone . now
@@ -60,17 +60,6 @@ def otp_action=(input)
6060 @otp_action = input . to_h
6161 end
6262
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-
7463 def enable_otp
7564 code = @otp_action [ :code ]
7665 if authenticate_otp ( code , drift : 60 )
@@ -89,4 +78,17 @@ def disable_otp
8978 errors . add ( :otp_code )
9079 end
9180 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
9294end
0 commit comments