diff --git a/config/locales/en.yml b/config/locales/en.yml index a91e9f8..3f2bcac 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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.' @@ -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...' @@ -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! diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb index 83ad661..75a3d4c 100644 --- a/lib/deploygate/api/v1/user.rb +++ b/lib/deploygate/api/v1/user.rb @@ -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] diff --git a/lib/deploygate/commands/add_devices.rb b/lib/deploygate/commands/add_devices.rb index 83c419f..f81019c 100644 --- a/lib/deploygate/commands/add_devices.rb +++ b/lib/deploygate/commands/add_devices.rb @@ -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 diff --git a/lib/deploygate/commands/deploy.rb b/lib/deploygate/commands/deploy.rb index 356949b..8f80685 100644 --- a/lib/deploygate/commands/deploy.rb +++ b/lib/deploygate/commands/deploy.rb @@ -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? diff --git a/lib/deploygate/commands/deploy/push.rb b/lib/deploygate/commands/deploy/push.rb index 39569c5..fd6dbcc 100644 --- a/lib/deploygate/commands/deploy/push.rb +++ b/lib/deploygate/commands/deploy/push.rb @@ -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 diff --git a/lib/deploygate/commands/login.rb b/lib/deploygate/commands/login.rb index feea3b0..a8771ba 100644 --- a/lib/deploygate/commands/login.rb +++ b/lib/deploygate/commands/login.rb @@ -1,6 +1,8 @@ module DeployGate module Commands class Login + class AccountNotFoundError < DeployGate::RavenIgnoreException; end + class << self # @return [void] @@ -8,31 +10,32 @@ 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 @@ -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 = "*" } diff --git a/lib/deploygate/user.rb b/lib/deploygate/user.rb index efa3f5e..51ea710 100644 --- a/lib/deploygate/user.rb +++ b/lib/deploygate/user.rb @@ -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] diff --git a/spec/deploygate/api/v1/user_spec.rb b/spec/deploygate/api/v1/user_spec.rb index f03ec46..7db9665 100644 --- a/spec/deploygate/api/v1/user_spec.rb +++ b/spec/deploygate/api/v1/user_spec.rb @@ -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'