| 11 | const config = require('../config.js'); |
| 12 | |
| 13 | class LoginCommand extends Command { |
| 14 | |
| 15 | constructor() { |
| 16 | |
| 17 | super('login'); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | help() { |
| 22 | |
| 23 | return { |
| 24 | description: 'Logs in to Autocode', |
| 25 | vflags: { |
| 26 | email: 'E-mail', |
| 27 | password: 'Password' |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | } |
| 32 | |
| 33 | run(params, callback) { |
| 34 | |
| 35 | let host = params.flags.h ? params.flags.h[0] : 'https://api.autocode.com'; |
| 36 | let port = params.flags.p && params.flags.p[0]; |
| 37 | |
| 38 | let email = params.vflags.email || params.vflags.email || [] |
| 39 | email = email[0]; |
| 40 | let password = params.vflags.password || params.vflags.password || []; |
| 41 | password = password[0]; |
| 42 | |
| 43 | let questions = []; |
| 44 | |
| 45 | email || questions.push({ |
| 46 | name: 'email', |
| 47 | type: 'input', |
| 48 | default: '', |
| 49 | message: 'Username or E-mail', |
| 50 | }); |
| 51 | |
| 52 | password || questions.push({ |
| 53 | name: 'password', |
| 54 | type: 'password', |
| 55 | message: 'Password', |
| 56 | }); |
| 57 | |
| 58 | let resource = new APIResource(host, port); |
| 59 | |
| 60 | let setAccessToken = (accessToken, cb) => { |
| 61 | |
| 62 | config.set('ACCESS_TOKEN', accessToken); |
| 63 | config.set('ACTIVE_LIBRARY_TOKEN', ''); |
| 64 | config.unset('LIBRARY_TOKENS'); |
| 65 | config.write(); |
| 66 | |
| 67 | console.log(); |
| 68 | console.log(chalk.bold.green('Logged in successfully!') + ' Retrieving default Identity Token (API Key)...'); |
| 69 | |
| 70 | resource.authorize(config.get('ACCESS_TOKEN')); |
nothing calls this directly
no outgoing calls
no test coverage detected