Class: FaaStRuby::Command::Account::Signup

Inherits:
AccountBaseCommand show all
Defined in:
lib/faastruby/cli/commands/account/signup.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AccountBaseCommand

#password_is_confirmed?, #password_is_valid?, #prompt, #prompt_for_password, #prompt_to_confirm_password

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ Signup

Returns a new instance of Signup.



7
8
9
10
11
# File 'lib/faastruby/cli/commands/account/signup.rb', line 7

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

Class Method Details

.helpObject



40
41
42
# File 'lib/faastruby/cli/commands/account/signup.rb', line 40

def self.help
  "signup"
end

Instance Method Details

#email_is_valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/faastruby/cli/commands/account/signup.rb', line 36

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

#parse_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/faastruby/cli/commands/account/signup.rb', line 48

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

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/faastruby/cli/commands/account/signup.rb', line 13

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

#usageObject



44
45
46
# File 'lib/faastruby/cli/commands/account/signup.rb', line 44

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