Skip to content

Commit

Permalink
Merge pull request #293 from DeployGate/delete-signup
Browse files Browse the repository at this point in the history
Delete new registration flow line from CLI
  • Loading branch information
jiikko authored Jan 7, 2022
2 parents 93db3e5 + 489aaf6 commit e54de68
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 158 deletions.
25 changes: 2 additions & 23 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
en:
errors:
check_update_failure: 'Checking update failed'
account_not_found_error: 'Your account was not found. Please create it from https://deploygate.com'
command_builder:
name: 'dg'
description: 'Control DeployGate from your terminal.'
Expand Down Expand Up @@ -95,7 +96,7 @@ en:
$ dg login
print_login_user: 'User name: %{name}'
login:
start_login_or_create_account:
start_login:
welcome: 'Welcome to DeployGate!'
email: 'Email: '
check_account: 'Checking for your account...'
Expand All @@ -105,28 +106,6 @@ en:
Could not log in to DeployGate.
Please try again.
success: 'Hello %{name}!'
create_account:
prompt: "Looks new to DeployGate. Let's set up your account, just choose your user name and password."
creating: 'Creating your account... '
error: |
Could not create your account.
Please try again.
success: 'done! Your account has been set up successfully.'
input_new_account_name:
input_user_name: 'Username: '
checking: 'Checking for availability... '
already_used_user_name: 'Sorry, %{user_name} was already taken. Please try again.'
success: 'Good, %{user_name} is available.'
input_new_account_password:
input_password: 'Password: '
input_same_password: 'Type the same password: '
error: "Passwords didn't match. Please type again."
check_terms:
terms_url: 'Terms of Service: https://deploygate.com/terms'
privacy_url: 'Privacy Policy: https://deploygate.com/terms/privacy'
note: "DeployGate properly manages your account information under GDPR, Japan's Personal Information Protection Act and our Privacy Policy."
text: 'I agree to the Terms of Service and Privacy Policy (y/n) '
error: 'You must agree to the Terms of Service and Privacy Policy.'
logout:
success: |
Logout success!
Expand Down
24 changes: 0 additions & 24 deletions lib/deploygate/api/v1/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@ class User
ENDPOINT = '/users'

class << self
# @param [String] name
# @param [String] email
# @param [String] password
# @param [String] locale
# @return [Hash]
def create(name, email, password, locale = 'en')
res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password, :locale => locale})

user_create_results = {
:error => res['error'],
:message => res['because']
}

results = res['results']
unless results.nil?
user_create_results.merge!({
:name => results['user']['name'],
:token => results['api_token']
})
end

user_create_results
end

# @param [String] name
# @param [String] email
# @return [Boolean]
Expand Down
2 changes: 1 addition & 1 deletion lib/deploygate/commands/add_devices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def run(args, options)

session = DeployGate::Session.new
unless session.login?
Login.start_login_or_create_account()
Login.start_login()
session = DeployGate::Session.new()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/deploygate/commands/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self
# @param [Array] args
# @param [Commander::Command::Options] options
def run(args, options)
Login.start_login_or_create_account() unless DeployGate::Session.new.login?
Login.start_login() unless DeployGate::Session.new.login?

# push or build(android/ios)
args.push(Dir.pwd) if args.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/deploygate/commands/deploy/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
def upload(args, options)
session = DeployGate::Session.new()
unless session.login?
Login.start_login_or_create_account()
Login.start_login()
session = DeployGate::Session.new()
end

Expand Down
80 changes: 10 additions & 70 deletions lib/deploygate/commands/login.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
module DeployGate
module Commands
class Login
class AccountNotFoundError < DeployGate::RavenIgnoreException; end

class << self

# @return [void]
def run(args, options)
welcome()

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

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

# @return [void]
def start_login_or_create_account
# @raise [AccountNotFoundError] emailに一致するUserが存在しないとき
def start_login
puts ''
email = ask(I18n.t('commands.login.start_login_or_create_account.email'))
email = ask(I18n.t('commands.login.start_login.email'))

puts ''
puts I18n.t('commands.login.start_login_or_create_account.check_account')
puts I18n.t('commands.login.start_login.check_account')
if DeployGate::User.registered?('', email)
puts ''
password = input_password(I18n.t('commands.login.start_login_or_create_account.input_password'))
password = input_password(I18n.t('commands.login.start_login.input_password'))
puts ''
start(email, password)
else
create_account(email)
raise AccountNotFoundError, HighLine.color(I18n.t('errors.account_not_found_error'))
end
end

Expand All @@ -56,69 +59,6 @@ def login_success
puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN)
end

# @param [String] email
# @return [void]
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

# @return [String]
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

# @return [String]
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

# @return [boolean]
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

# @return [String]
def input_password(message)
ask(message) { |q| q.echo = "*" }
Expand Down
11 changes: 0 additions & 11 deletions lib/deploygate/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ def initialize(name)
@name = name
end

# @param [String] name
# @param [String] email
# @param [String] password
# @return [DeployGate::User]
def self.create(name, email, password)
locale = Locale.current.language
results = DeployGate::API::V1::User.create(name, email, password, locale)
return if results[:error]
DeployGate::User.new(results[:name])
end

# @param [String] name
# @param [String] email
# @return [Boolean]
Expand Down
27 changes: 0 additions & 27 deletions spec/deploygate/api/v1/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
describe DeployGate::API::V1::User do
describe "#create" do
it "success" do
name = 'test'
email = 'email'
password = 'password'
token = 'token'
response = {
:error => false,
:because => '',
:results => {
:user => {:name => name},
:api_token => token
}
}
stub_request(:post, "#{API_ENDPOINT}/users").
to_return(:body => response.to_json)

results = DeployGate::API::V1::User.create(name, email, password)
expect(results).to eq({
:error => response[:error],
:message => response[:because],
:name => name,
:token => token
})
end
end

describe "#registered?" do
it "registered" do
name = 'test'
Expand Down

0 comments on commit e54de68

Please sign in to comment.