Class: RailsBase::Authentication::ModifyPassword
Constant Summary
collapse
- FLOW_TYPES =
[:forgot_password, :user_settings]
Instance Method Summary
collapse
included, #validate_complement?, #validate_full_name?, #validate_name?, #validate_password?
Methods inherited from ServiceBase
inherited, #internal_validate, #service_base_logging
#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id
Instance Method Details
#call ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/services/rails_base/authentication/modify_password.rb', line 14
def call
valid_password = validate_password?(password: password, password_confirmation: password_confirmation)
unless valid_password[:status]
context.fail!(message: valid_password[:msg])
end
if user.nil?
log(level: :error, msg: "Could not find [#{user_id}]. 5xx error with user deletion most likely")
context.fail!(message: "Unknown error. Please try again")
end
case flow
when :forgot_password
forgot_password
else
end
unless user.update(password: password, password_confirmation: password_confirmation)
context.fail!(message: "Failed to update user. Please try again")
end
log(level: :info, msg: "Successfully update users password")
end
|
#forgot_password ⇒ Object
37
38
39
40
41
|
# File 'app/services/rails_base/authentication/modify_password.rb', line 37
def forgot_password
return if valid_short_term_data_point?
context.fail!(message: Constants::MV_FISHY)
end
|
#user ⇒ Object
54
55
56
|
# File 'app/services/rails_base/authentication/modify_password.rb', line 54
def user
@user ||= current_user || User.find_by_id(user_id)
end
|
#valid_short_term_data_point? ⇒ Boolean
43
44
45
46
47
48
49
50
51
52
|
# File 'app/services/rails_base/authentication/modify_password.rb', line 43
def valid_short_term_data_point?
raise 'Expected data to be defined' if data.nil?
data_point = ShortLivedData.get_by_data(data: data, reason: Constants::VFP_REASON)
datum_user_id = data_point&.user_id
log(level: :info, msg: "Found ShortLivedData with data #{data[0..15]}... attached to user [#{datum_user_id}]")
datum_user_id && (datum_user_id.to_i == user_id.to_i)
end
|
#validate! ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'app/services/rails_base/authentication/modify_password.rb', line 58
def validate!
raise "Expected Flow to be present and a Symbol" unless flow.is_a? Symbol
raise "Expected Flow to be in #{FLOW_TYPES}" unless FLOW_TYPES.include?(flow)
raise "Expected password to be a String. Received #{password.class}" unless password.is_a? String
raise "Expected password_confirmation to be a String. Received #{password_confirmation.class}" unless password_confirmation.is_a? String
raise "Expected user_id to be present." if current_user.nil? && user_id.nil?
raise "Expected data to be present." if current_user.nil? && data.nil?
end
|