class Gleis::Authentication
This class implements all authentication related commands of the CLI
Public Class Methods
login(username, password = nil, skip_keygen = false)
click to toggle source
# File lib/gleis/authentication.rb, line 4 def self.login(username, password = nil, skip_keygen = false) puts 'Login to Gleis' username = username.downcase password ||= Utils.prompt_password body = API.request('post', 'login', nil, 'username': username, 'password': password) token = body['token'] Token.save(token) puts 'Authentication successful' puts "\nNEWS: #{body['data']}\n\n" unless body['data'].nil? # Generate SSH key pair if not found and upload pub key ssh_key_filename = Config::SSH_KEY_FILE_BASE + '_' + Utils.convert_username_to_filename(username) AuthKey.add("#{ssh_key_filename}.pub", nil, true) \ if skip_keygen == false && SSH.generate_key(ssh_key_filename, username) puts "\nINFO: New Gleis CLI version available, please update by running \"gem update gleis\"\n\n" \ if Utils.update_available?(Params.get_cli_parameters(token)['version']) end
logout()
click to toggle source
# File lib/gleis/authentication.rb, line 58 def self.logout token = Token.check puts 'Logout of Gleis' API.request('post', 'logout', token, {}) Token.delete puts 'Logout successful' end
register(email)
click to toggle source
# File lib/gleis/authentication.rb, line 23 def self.register(email) abort('Invalid e-mail address.') unless email.match(URI::MailTo::EMAIL_REGEXP) puts "In order to register for a free Gleis account please enter your details below.\n\n" print "Email: #{email}\n" print 'First name: ' firstname = $stdin.gets.chomp print 'Last name: ' lastname = $stdin.gets.chomp print 'Organisation or company name (optional): ' organisation = $stdin.gets.chomp puts "\n" abort('Please provide your firstname and lastname.') if firstname.empty? || lastname.empty? return unless Utils.prompt_yes_no('Are your details above correct?') req_body = { 'email': email, 'firstname': firstname, 'lastname': lastname, 'organisation': organisation } body = API.request('post', 'register', nil, req_body) if body['success'] == 1 puts 'Successfully sent registration. We will manually review your request and send you a confirmation ' \ "e-mail within the next 24 hours.\n" puts 'In the meantime please save and keep secure your Gleis password shown below in your password manager:' puts "\n\n\t\t#{body['data']}\n\n" else puts "Failed to register: #{body['message']}" end end
whoami()
click to toggle source
# File lib/gleis/authentication.rb, line 52 def self.whoami token = Token.check body = API.request('get', 'whoami', token) puts "You are currently logged in as #{body['data']}" end