Class: Foobara::Auth::ResetPassword
- Defined in:
- foobara-auth-0.0.9/src/reset_password.rb
Defined Under Namespace
Classes: BothPasswordResetTokenAndOldPasswordGivenError, IncorrectOldPasswordError, InvalidResetPasswordTokenError, NoPasswordResetTokenOrOldPasswordGivenError, UserNotFoundForResetTokenError, UserNotGivenError
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#password_secret ⇒ Object
Returns the value of attribute password_secret.
-
#reset_password_token_record ⇒ Object
Returns the value of attribute reset_password_token_record.
- #user ⇒ Object
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #build_new_password ⇒ Object
-
#execute ⇒ Object
TODO: should we enforce certain password requirements?.
- #load_user ⇒ Object
- #old_password_given? ⇒ Boolean
- #reset_password_token_given? ⇒ Boolean
- #set_password_on_user ⇒ Object
- #validate ⇒ Object
- #verify_and_use_up_password_reset_token ⇒ Object
- #verify_old_password ⇒ Object
Methods inherited from Command
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from CommandPatternImplementation::Concerns::Reflection
Methods included from CommandPatternImplementation::Concerns::DomainMappers
#domain_map, #domain_map!, #run_mapped_subcommand!
Methods included from CommandPatternImplementation::Concerns::Subcommands
#run_subcommand!, #subcommand?
Methods included from CommandPatternImplementation::Concerns::Entities
Methods included from CommandPatternImplementation::Concerns::Transactions
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Runtime
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate_records
Methods included from CommandPatternImplementation::Concerns::Errors
Methods included from CommandPatternImplementation::Concerns::Inputs
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
Methods included from TruncatedInspect
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs
Instance Attribute Details
#password_secret ⇒ Object
Returns the value of attribute password_secret.
74 75 76 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 74 def password_secret @password_secret end |
#reset_password_token_record ⇒ Object
Returns the value of attribute reset_password_token_record.
74 75 76 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 74 def reset_password_token_record @reset_password_token_record end |
#user ⇒ Object
110 111 112 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 110 def user @user || inputs[:user] end |
Instance Method Details
#build_new_password ⇒ Object
114 115 116 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 114 def build_new_password self.password_secret = run_subcommand!(BuildSecret, secret: new_password) end |
#execute ⇒ Object
TODO: should we enforce certain password requirements?
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 45 def execute if old_password_given? verify_old_password else verify_and_use_up_password_reset_token load_user end build_new_password set_password_on_user user end |
#load_user ⇒ Object
102 103 104 105 106 107 108 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 102 def load_user self.user = Types::User.that_owns(reset_password_token_record, "reset") unless user add_runtime_error(UserNotFoundForResetTokenError) end end |
#old_password_given? ⇒ Boolean
77 78 79 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 77 def old_password_given? !!old_password end |
#reset_password_token_given? ⇒ Boolean
81 82 83 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 81 def reset_password_token_given? !!reset_password_token_secret end |
#set_password_on_user ⇒ Object
118 119 120 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 118 def set_password_on_user user.password_secret = password_secret end |
#validate ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 59 def validate if old_password_given? unless user add_runtime_error(UserNotGivenError) end if reset_password_token_given? add_runtime_error(BothPasswordResetTokenAndOldPasswordGivenError) end else unless reset_password_token_given? add_runtime_error(NoPasswordResetTokenOrOldPasswordGivenError) end end end |
#verify_and_use_up_password_reset_token ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 91 def verify_and_use_up_password_reset_token verified_result = run_subcommand!(VerifyToken, token_string: reset_password_token_secret) unless verified_result[:verified] add_runtime_error(InvalidResetPasswordTokenError) end self.reset_password_token_record = verified_result[:token_record] reset_password_token_record.use_up! end |
#verify_old_password ⇒ Object
85 86 87 88 89 |
# File 'foobara-auth-0.0.9/src/reset_password.rb', line 85 def verify_old_password unless run_subcommand!(VerifyPassword, user:, plaintext_password: old_password) add_runtime_error(IncorrectOldPasswordError) end end |