Class: RailsBase::Authentication::SendVerificationEmail
- Inherits:
-
ServiceBase
- Object
- ServiceBase
- RailsBase::Authentication::SendVerificationEmail
show all
- Includes:
- ActionView::Helpers::DateHelper, VelocityLimiter
- Defined in:
- app/services/rails_base/authentication/send_verification_email.rb
Constant Summary
collapse
- DATA_USE =
:alphanumeric
- VELOCITY_MAX =
5
- VELOCITY_MAX_IN_FRAME =
10.minutes
- VELOCITY_FRAME =
1.hour
- REASON_MAPPER =
{
Constants::SVE_LOGIN_REASON => {
method: :email_verification,
url_method: :email_verification_url,
max_use: RailsBase.config.login_behavior.email_max_use_verification
},
Constants::SVE_FORGOT_REASON => {
method: :forgot_password,
url_method: :forgot_password_auth_url,
max_use: RailsBase.config.login_behavior.email_max_use_forgot
}
}
Instance Method Summary
collapse
#_velocity_limiter_params_validator!, #cache_delineator, #velocity_limit_message, #velocity_limit_reached?, #vl_metadata, #vl_read, #vl_time, #vl_write!
Methods inherited from ServiceBase
inherited, #internal_validate, #service_base_logging
#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id
Instance Method Details
#assign_url(data) ⇒ Object
#cache_key ⇒ Object
93
94
95
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 93
def cache_key
"#{self.class.name.downcase}.#{user.id}"
end
|
#call ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 29
def call
velocity = velocity_limit_reached?
if velocity[:reached]
context.fail!(message: velocity[:msg])
end
data_point = create_short_lived_data
begin
url = assign_url(data_point.data)
rescue StandardError => e
log(level: :error, msg: "Error: #{e.class}")
log(level: :error, msg: "Error: #{e.message}")
log(level: :error, msg: "Failed to get url for #{url_method}")
log(level: :error, msg: "Swallowing Error. Returning to user")
context.fail!(message: "Unknown error occurred. Please log in with credentials to restart process")
return
end
log(level: :info, msg: "SSO url for user #{user.id}: #{url}")
begin
RailsBase::EmailVerificationMailer.public_send(method, user: user, url: url).deliver_me
rescue StandardError => e
log(level: :error, msg: "Unkown error occured when sending EmailVerificationMailer.#{method}")
log(level: :error, msg: "Params: #{method}, #{reason}, user: #{user.id}")
log(level: :error, msg: e.message)
context.fail!(message: "Unknown error occurred. Please log in with credentials to restart process")
return
end
log(level: :info, msg: "Succesfully sent EmailVerificationMailer.#{method} to #{user.id} @ #{user.email}")
end
|
#create_short_lived_data ⇒ Object
#method ⇒ Object
97
98
99
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 97
def method
REASON_MAPPER[reason][:method]
end
|
#url_method ⇒ Object
101
102
103
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 101
def url_method
REASON_MAPPER[reason][:url_method]
end
|
#validate! ⇒ Object
105
106
107
108
109
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 105
def validate!
raise "Expected user to be a User. Received #{user.class}" unless user.is_a? User
raise "Expected reason to be a symbol. Received #{reason.class}" unless reason.is_a? Symbol
raise "Expected #{reason} to be in #{REASON_MAPPER.keys}" unless REASON_MAPPER.keys.include?(reason)
end
|
#velocity_frame ⇒ Object
89
90
91
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 89
def velocity_frame
VELOCITY_FRAME
end
|
#velocity_max ⇒ Object
85
86
87
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 85
def velocity_max
VELOCITY_MAX
end
|
#velocity_max_in_frame ⇒ Object
81
82
83
|
# File 'app/services/rails_base/authentication/send_verification_email.rb', line 81
def velocity_max_in_frame
VELOCITY_MAX_IN_FRAME
end
|