Class: DeployGate::Commands::Login

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

Class Method Summary collapse

Class Method Details

.create_account(email) ⇒ void

This method returns an undefined value.

Parameters:

  • email (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/deploygate/commands/login.rb', line 61

def (email)
  puts I18n.t('commands.login.create_account.prompt')
  puts ''

  name = ()
  puts ''

  password = ()
  puts ''

  print I18n.t('commands.login.create_account.creating')
  if DeployGate::User.create(name, email, password).nil?
    puts HighLine.color(I18n.t('commands.login.create_account.error'), HighLine::RED)
    raise 'User create error'
  else
    puts HighLine.color(I18n.t('commands.login.create_account.success'), HighLine::GREEN)
    start(email, password)
  end
end

.input_new_account_nameString

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/deploygate/commands/login.rb', line 82

def 
  user_name = ask(I18n.t('commands.login.input_new_account_name.input_user_name'))
  print I18n.t('commands.login.input_new_account_name.checking')

  if DeployGate::User.registered?(user_name, '')
    puts HighLine.color(I18n.t('commands.login.input_new_account_name.already_used_user_name', user_name: user_name), HighLine::RED)
    return ()
  else
    puts HighLine.color(I18n.t('commands.login.input_new_account_name.success', user_name: user_name), HighLine::GREEN)
    return user_name
  end
end

.input_new_account_passwordString

Returns:

  • (String)


96
97
98
99
100
101
102
103
104
105
106
# File 'lib/deploygate/commands/login.rb', line 96

def 
  password = input_password(I18n.t('commands.login.input_new_account_password.input_password'))
  secound_password = input_password(I18n.t('commands.login.input_new_account_password.input_same_password'))

  if password == secound_password
    return password
  else
    puts HighLine.color(I18n.t('commands.login.input_new_account_password.error'), HighLine::RED)
    return ()
  end
end

.input_password(message) ⇒ String

Returns:

  • (String)


109
110
111
# File 'lib/deploygate/commands/login.rb', line 109

def input_password(message)
  ask(message) { |q| q.echo = "*" }
end

.login_successObject



54
55
56
57
# File 'lib/deploygate/commands/login.rb', line 54

def 
  session = Session.new
  puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN)
end


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/deploygate/commands/login.rb', line 113

def print_deploygate_aa
  puts <<'EOF'
 _            _                       _
| |          | |                     | |
      __| | ___  ___ | | ___ _   ,____   ___ | |_ ___
     / _` |/ _ \' _ \| |/ _ \ \ / / _ \ / _ `| __/ _ \
    | (_| |  __/ |_) | | (_) \ v / (_| | (_| | |_' __/
     \___, \___| .__/|_|\___/ ` / \__, |\__,_|\__\___`
       |_|           /_/  |___/
EOF
end

.run(args, options) ⇒ void

This method returns an undefined value.



7
8
9
10
11
12
13
14
15
# File 'lib/deploygate/commands/login.rb', line 7

def run(args, options)
  welcome()

  if options.terminal
    ()
  else
    DeployGate::BrowserLogin.new().start()
  end
end

.start(email, password) ⇒ void

This method returns an undefined value.

Parameters:

  • email (String)
  • password (String)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/deploygate/commands/login.rb', line 42

def start(email, password)
  begin
    Session.(email, password)
  rescue Session::LoginError => e
    # login failed
    puts HighLine.color(I18n.t('commands.login.start.login_error'), HighLine::RED)
    raise e
  end

  ()
end

.start_login_or_create_accountvoid

This method returns an undefined value.



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

def 
  puts ''
  email = ask(I18n.t('commands.login.start_login_or_create_account.email'))

  puts ''
  puts I18n.t('commands.login.start_login_or_create_account.check_account')
  if DeployGate::User.registered?('', email)
    puts ''
    password = input_password(I18n.t('commands.login.start_login_or_create_account.input_password'))
    puts ''
    start(email, password)
  else
    (email)
  end
end

.welcomeObject



17
18
19
20
# File 'lib/deploygate/commands/login.rb', line 17

def welcome
  puts I18n.t('commands.login.start_login_or_create_account.welcome')
  print_deploygate_aa()
end