Class: Mozzn::Commands::Auth
Instance Method Summary collapse
Instance Method Details
#login ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mozzn/commands/auth.rb', line 47 def login mozzn = Mozzn::Api.new if [:email].nil? && [:password].nil? hl = HighLine.new email = hl.ask 'Mozzn email: ' password = hl.ask('Mozzn password (we will not store this): ') { |q| q.echo = "*" } elsif [:email].nil? || [:password].nil? raise Thor::Error, "Email and password must be provided!" else email = [:email] password = [:password] end params = { user: { email: email, password: password } } response = mozzn.post(:sessions, params) auth_token = response['data']['auth_token'] if auth_token == nil raise Thor::Error, response['info'] else Mozzn::Config.new.add('token', auth_token) say response['info'], :green git_check ssh_key_check end rescue Mozzn::Disconnected say 'Unable to connect to Mozzn. Please check your internet connection.', :red rescue Mozzn::UnexpectedOutput say 'UnexpectedOutput', :red end |
#register ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mozzn/commands/auth.rb', line 10 def register mozzn = Mozzn::Api.new if .present? name = [:name] email = [:email] password = [:password] password_confirmation = [:password_confirmation] else h = HighLine.new name = h.ask("Username: ") email = h.ask("Email: ") password = h.ask("Password: ") password_confirmation = h.ask("password_confirmation: ") end params = { user: { name: name, email: email, password: password, password_confirmation: password_confirmation } } response = mozzn.post(:registrations, params) errors = response['data']['errors'] if errors.present? errors = JSON.parse(errors) say "#{response['info']}, the following errors were found:\n * #{errors.map {|e| e.join(' ')}.join("\n * ")}\nPlease try again.", :red # TODO: re-run registration else say response['info'], :green end end |