Class: FIS::CLI::Commands::Login

Inherits:
FIS::Command show all
Defined in:
lib/fis/cli/commands/login.rb

Overview

‘auth login` - Requests and adds the user’s authentication credentials

Instance Method Summary collapse

Methods inherited from FIS::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ Login

Returns a new instance of Login.



8
9
10
11
# File 'lib/fis/cli/commands/login.rb', line 8

def initialize(options)
  @options = options
  @auth_local_server = FIS::Auth::Runner.new
end

Instance Method Details

#executeObject



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

def execute
  # TODO: Allow for token to be set with a flag

  FIS.ui.newline

  return FIS.ui.error("You're already logged in. Please run `fis auth logout` to continue.") if logged_in?
  return FIS.ui.warn('OAuth not available. Please set your token using the `--token` flag.') if remote_ide?

  @auth_local_server.start

  FIS.ui.info('Logging into your Flatiron School account...')
  open_browser!

  sleep 1 until token_accessible? # TODO: Timeout?

  FIS.ui.newline

  FIS.ui.ok("You've successfully logged in.")
ensure
  @auth_local_server.stop
end