Class: Foobara::Auth::Login

Inherits:
Command
  • Object
show all
Defined in:
foobara-auth-0.1.1/src/login.rb

Defined Under Namespace

Classes: InvalidPasswordError, NoUserIdEmailOrUsernameGivenError

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

install!

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



41
42
43
# File 'src/login.rb', line 41

def access_token
  @access_token
end

#refresh_token_textObject

Returns the value of attribute refresh_token_text.



41
42
43
# File 'src/login.rb', line 41

def refresh_token_text
  @refresh_token_text
end

#user_to_loginObject

Returns the value of attribute user_to_login.



41
42
43
# File 'src/login.rb', line 41

def 
  @user_to_login
end

Instance Method Details

#executeObject



32
33
34
35
36
37
38
39
# File 'src/login.rb', line 32

def execute
  
  verify_password
  generate_access_token
  generate_new_refresh_token

  tokens
end

#find_user_to_loginObject



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 'src/login.rb', line 43

def 
  if user
    self. = user
  elsif username
    self. = run_subcommand!(FindUser, username:)
  elsif email
    self. = run_subcommand!(FindUser, email:)
  elsif username_or_email
    begin
      self. = 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.first.is_a?(FindUser::UserNotFoundError) &&
         username_or_email.include?("@")
        error_collection.clear
        self. = run_subcommand!(FindUser, email: username_or_email)
      else
        raise
      end
    end
  else
    add_runtime_error(NoUserIdEmailOrUsernameGivenError)
  end
end

#generate_access_tokenObject



75
76
77
# File 'src/login.rb', line 75

def generate_access_token
  self.access_token = run_subcommand!(BuildAccessToken, user: )
end

#generate_new_refresh_tokenObject



79
80
81
# File 'src/login.rb', line 79

def generate_new_refresh_token
  self.refresh_token_text = run_subcommand!(CreateRefreshToken, user: )
end

#tokensObject



83
84
85
86
87
88
# File 'src/login.rb', line 83

def tokens
  {
    access_token:,
    refresh_token: refresh_token_text
  }
end

#verify_passwordObject



69
70
71
72
73
# File 'src/login.rb', line 69

def verify_password
  unless run_subcommand!(VerifyPassword, user: , plaintext_password:)
    add_runtime_error(InvalidPasswordError)
  end
end