Class: DeployGate::Commands::Login
- Inherits:
-
Object
- Object
- DeployGate::Commands::Login
- Defined in:
- lib/deploygate/commands/login.rb
Class Method Summary collapse
- .check_terms ⇒ boolean
- .create_account(email) ⇒ void
- .input_new_account_name ⇒ String
- .input_new_account_password ⇒ String
- .input_password(message) ⇒ String
- .login_success ⇒ Object
- .print_deploygate_aa ⇒ Object
- .run(args, options) ⇒ void
- .start(email, password) ⇒ void
- .start_login_or_create_account ⇒ void
- .welcome ⇒ Object
Class Method Details
.check_terms ⇒ boolean
114 115 116 117 118 119 120 |
# File 'lib/deploygate/commands/login.rb', line 114 def check_terms puts I18n.t('commands.login.check_terms.terms_url') puts I18n.t('commands.login.check_terms.privacy_url') puts I18n.t('commands.login.check_terms.note') puts '' HighLine.agree(I18n.t('commands.login.check_terms.text')) {|q| q.default = "n"} end |
.create_account(email) ⇒ void
This method returns an undefined value.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/deploygate/commands/login.rb', line 61 def create_account(email) puts I18n.t('commands.login.create_account.prompt') puts '' name = input_new_account_name() puts '' password = input_new_account_password() puts '' unless check_terms puts HighLine.color(I18n.t('commands.login.check_terms.error'), HighLine::RED) exit 1 end 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_name ⇒ String
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/deploygate/commands/login.rb', line 87 def input_new_account_name 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 input_new_account_name() 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_password ⇒ String
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/deploygate/commands/login.rb', line 101 def input_new_account_password 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 input_new_account_password() end end |
.input_password(message) ⇒ String
123 124 125 |
# File 'lib/deploygate/commands/login.rb', line 123 def input_password() ask() { |q| q.echo = "*" } end |
.login_success ⇒ Object
54 55 56 57 |
# File 'lib/deploygate/commands/login.rb', line 54 def login_success session = Session.new puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN) end |
.print_deploygate_aa ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/deploygate/commands/login.rb', line 127 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, ) welcome() if .terminal start_login_or_create_account() else DeployGate::BrowserLogin.new().start() end end |
.start(email, password) ⇒ void
This method returns an undefined value.
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.login(email, password) rescue Session::LoginError => e # login failed puts HighLine.color(I18n.t('commands.login.start.login_error'), HighLine::RED) raise e end login_success() end |
.start_login_or_create_account ⇒ void
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 start_login_or_create_account 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 create_account(email) end end |
.welcome ⇒ Object
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 |