| 90 | } |
| 91 | |
| 92 | let loopCb = async (err) => { |
| 93 | |
| 94 | err && errorLog(err); |
| 95 | |
| 96 | let promptResult = await inquirer.prompt(questions); |
| 97 | |
| 98 | email = promptResult.email || email; |
| 99 | password = promptResult.password || password; |
| 100 | |
| 101 | resource.request('v1/login').create({}, {grant_type: 'password', username: email, password: password}, (err, response) => { |
| 102 | |
| 103 | if (err) { |
| 104 | questions.filter(q => q.name === 'email').forEach(q => q.default = email); |
| 105 | password = null; |
| 106 | return loopCb(err); |
| 107 | } |
| 108 | |
| 109 | if (!!response.data[0].factor_identifier) { |
| 110 | console.log(); |
| 111 | console.log(`Your account has two-factor authentication enabled. Please enter a valid verification code from your device to finish logging in.`); |
| 112 | console.log(); |
| 113 | inquirer.prompt({ |
| 114 | name: 'verificationCode', |
| 115 | type: 'input', |
| 116 | default: '', |
| 117 | message: 'Verification Code', |
| 118 | }).then((promptResult) => { |
| 119 | resource.request('v1/login').create({}, { |
| 120 | grant_type: 'password', |
| 121 | username: email, |
| 122 | password: password, |
| 123 | factor_verification_check_sid: response.data[0].sid, |
| 124 | factor_verification_code: promptResult.verificationCode, |
| 125 | }, (err, response) => { |
| 126 | if (err) { |
| 127 | questions.filter(q => q.name === 'email').forEach(q => q.default = email); |
| 128 | password = null; |
| 129 | return loopCb(err); |
| 130 | } |
| 131 | setAccessToken(response.data[0].access_token, callback); |
| 132 | }); |
| 133 | }); |
| 134 | } else { |
| 135 | setAccessToken(response.data[0].access_token, callback); |
| 136 | } |
| 137 | |
| 138 | }); |
| 139 | |
| 140 | }; |
| 141 | |
| 142 | loopCb(); |
| 143 | |