Sha256: 88da7c056f272c32baa1b327c445edfb2dd7747d222f246cde9d26b0759a20ad

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

module FaaStRuby
  module Command
    module Account
      require 'faastruby/cli/commands/account/base_command'
      require 'io/console'
      class Signup < AccountBaseCommand
        def initialize(args)
          @args = args
          parse_options
          FaaStRuby::CLI.error("You are currently logged in. Please run 'faastruby logout' to logout, then try again.") if has_user_logged_in?
        end

        def run
          email = prompt(command: "Welcome to FaaStRuby! Please enter your email address.", label: "Email: ", secure: false)

          until email_is_valid?(email) do
            email = prompt(command: "\nYou entered an invalid email address. Please try again.".red, label: "Email: ", secure: false)
          end

          password = prompt_for_password

          prompt_to_confirm_password(password)

          spinner = spin("Creating your account...")
          user = User.create(email: email, password: password)
          if user.errors.any?
            spinner.error
            FaaStRuby::CLI.error(user.errors)
          end

          spinner.success
          exec("faastruby confirm-account --email #{email}")
          exit 0
        end

        def email_is_valid?(email)
          email.match(EMAIL_REGEX)
        end

        def self.help
          "signup"
        end

        def usage
          puts "Usage: faastruby #{self.class.help}"
        end

        def parse_options
          @options = {}
          while @args.any?
            option = @args.shift
            case option
            when '-h', '--help', 'help'
              usage
              exit 0
            else
              FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faastruby-0.5.30 lib/faastruby/cli/commands/account/signup.rb
faastruby-0.5.29 lib/faastruby/cli/commands/account/signup.rb
faastruby-0.5.28 lib/faastruby/cli/commands/account/signup.rb
faastruby-0.5.27 lib/faastruby/cli/commands/account/signup.rb
faastruby-0.5.26 lib/faastruby/cli/commands/account/signup.rb
faastruby-0.5.25 lib/faastruby/cli/commands/account/signup.rb