7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/active_model/one_time_password.rb', line 7
def has_one_time_password(options = {})
cattr_accessor :otp_column_name, :otp_counter_column_name
class_attribute :otp_digits, :otp_counter_based
self.otp_column_name = (options[:column_name] || "otp_secret_key").to_s
self.otp_digits = options[:length] || 6
self.otp_counter_based = (options[:counter_based] || false)
self.otp_counter_column_name = (
options[:counter_column_name] || "otp_counter"
).to_s
include InstanceMethodsOnActivation
before_create do
self.otp_regenerate_secret if !otp_column
self.otp_regenerate_counter if otp_counter_based && !otp_counter
end
if respond_to?(:attributes_protected_by_default)
def self.attributes_protected_by_default super + [otp_column_name, otp_counter_column_name]
end
end
end
|