Class: Foobara::Auth::Login
- Defined in:
- foobara-auth-0.0.13/src/login.rb
Defined Under Namespace
Classes: InvalidPasswordError, NoUserIdEmailOrUsernameGivenError
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#refresh_token_text ⇒ Object
Returns the value of attribute refresh_token_text.
-
#user_to_login ⇒ Object
Returns the value of attribute user_to_login.
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
- #execute ⇒ Object
- #find_user_to_login ⇒ Object
- #generate_access_token ⇒ Object
- #generate_new_refresh_token ⇒ Object
- #tokens ⇒ Object
- #verify_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
Methods included from NestedTransactionable
#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Runtime
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #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
#access_token ⇒ Object
Returns the value of attribute access_token.
41 42 43 |
# File 'foobara-auth-0.0.13/src/login.rb', line 41 def access_token @access_token end |
#refresh_token_text ⇒ Object
Returns the value of attribute refresh_token_text.
41 42 43 |
# File 'foobara-auth-0.0.13/src/login.rb', line 41 def refresh_token_text @refresh_token_text end |
#user_to_login ⇒ Object
Returns the value of attribute user_to_login.
41 42 43 |
# File 'foobara-auth-0.0.13/src/login.rb', line 41 def user_to_login @user_to_login end |
Instance Method Details
#execute ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'foobara-auth-0.0.13/src/login.rb', line 32 def execute find_user_to_login verify_password generate_access_token generate_new_refresh_token tokens end |
#find_user_to_login ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'foobara-auth-0.0.13/src/login.rb', line 43 def find_user_to_login if user self.user_to_login = user elsif username self.user_to_login = run_subcommand!(FindUser, username:) elsif email self.user_to_login = run_subcommand!(FindUser, email:) elsif username_or_email begin self.user_to_login = run_subcommand!(FindUser, username: username_or_email) rescue Halt # I'm a bit nervous about rescuing Halt and clearing the errors, but I'm more nervous bout # introducing a #run_subcommand method. if error_collection.size == 1 && error_collection.errors.first.is_a?(FindUser::UserNotFoundError) && username_or_email.include?("@") error_collection.clear self.user_to_login = run_subcommand!(FindUser, email: username_or_email) else raise end end else add_runtime_error(NoUserIdEmailOrUsernameGivenError) end end |
#generate_access_token ⇒ Object
75 76 77 |
# File 'foobara-auth-0.0.13/src/login.rb', line 75 def generate_access_token self.access_token = run_subcommand!(BuildAccessToken, user: user_to_login) end |
#generate_new_refresh_token ⇒ Object
79 80 81 |
# File 'foobara-auth-0.0.13/src/login.rb', line 79 def generate_new_refresh_token self.refresh_token_text = run_subcommand!(CreateRefreshToken, user: user_to_login) end |
#tokens ⇒ Object
83 84 85 86 87 88 |
# File 'foobara-auth-0.0.13/src/login.rb', line 83 def tokens { access_token:, refresh_token: refresh_token_text } end |
#verify_password ⇒ Object
69 70 71 72 73 |
# File 'foobara-auth-0.0.13/src/login.rb', line 69 def verify_password unless run_subcommand!(VerifyPassword, user: user_to_login, plaintext_password:) add_runtime_error(InvalidPasswordError) end end |