Class: Tane::Commands::Login

Inherits:
Base
  • Object
show all
Defined in:
lib/tane/commands/login.rb

Class Method Summary collapse

Methods inherited from Base

fire

Methods included from Helpers

included

Class Method Details

.display_errors_and_exit(errors) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tane/commands/login.rb', line 52

def display_errors_and_exit(errors)
  term.say "Couldn't signup - "

  errors.each do |field|
    term.say "\n"
    field.last.each do |error|
      term.say "  #{field.first} #{error} \n"
    end
  end
  exit
end

.display_help_messages_and_exitObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tane/commands/login.rb', line 65

def display_help_messages_and_exit
  messages = [
    "Please try one of the following:",
    "\t1. Log in again with different credentials",
    "\t2. Send us a help message from the command line via `tane support 'Hey guys, having trouble logging in with tane...'`",
    "\t3. Contact us by email at [email protected] if you're having trouble!",
    "Seriously, isn't it cool to be able to send a support message straight from the cli? It's like you're the fonz"]

  messages.each do |message|
    term.say message
  end
  
  exit
end

.help_textObject



80
81
82
83
84
85
86
87
88
# File 'lib/tane/commands/login.rb', line 80

def help_text
  <<-EOL
Usage:

tane login

Logs you into the Cloudfuji and stores the credentials in `~/.cloudfuji/credentials.yml` file. It only stores your email and an authentication token. Your password is not stored. This is required if you want to run local applications in a Cloudfuji environment. It prompts you to signup if you do not have a Cloudfuji account.
EOL
end

.process(args) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/tane/commands/login.rb', line 5

def process(args)
  email, password = warn_if_credentials_and_prompt
  
  auth_token = (email, password)
  
  term.say "Done!"
  term.say "Saving credentials"
  save_credentials(email, auth_token)
end

.signup_and_notify(email, password) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tane/commands/login.rb', line 41

def (email, password)
  term.say "Trying to sign up with those credentials..."
  auth_token, errors = Tane::Helpers::Cloudfuji.(email, password)

  display_errors_and_exit(errors) if auth_token.nil?
  
  term.say "Ok, you're signed up as #{email}!"
  return auth_token
end

.verify_or_signup(email, password) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tane/commands/login.rb', line 24

def (email, password)
  term.say "contacting cloudfuji, please wait..."
  auth_token, errors = Tane::Helpers::Cloudfuji.verify_credentials(email, password)
  
  return auth_token if not auth_token.nil?

  if auth_token.nil?
    term.say("Invalid username, or password, sorry! Don't worry though, we'll get you through this!")

    # returns auth_token on success
    return (email, password) if term.agree("would you like to try signing up with those credentials? Y/N")
      
    display_help_messages_and_exit
  end
end

.warn_if_credentials_and_promptObject



16
17
18
19
20
21
# File 'lib/tane/commands/login.rb', line 16

def warn_if_credentials_and_prompt
  warn_if_credentials
  
  term.say "Let's log you in:"
  email, password = prompt_for_credentials
end