Skip to content

Commit

Permalink
Merge pull request #33 from Fliplet/login/2fa
Browse files Browse the repository at this point in the history
Login/2fa
  • Loading branch information
seromenho authored Sep 27, 2017
2 parents fd093bd + cba7b08 commit c4664b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
25 changes: 21 additions & 4 deletions fliplet-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ program
.version(package.version)
.option('-u, --username <username>', 'Sets the username')
.option('-p, --password <password>', 'Sets the password')
.option('-c, --code <code>', 'Sets the 2FA code')
.parse(process.argv);

if (program.username && program.password) {
return login(program.username, program.password);
return login(program.username, program.password, program.code);
}

prompt.start();
Expand All @@ -35,13 +36,29 @@ prompt.get([
login(result.email, result.password);
});

function login(email, password) {
auth.login({ email, password })
function login(email, password, twofactor) {
auth.login({ email, password, twofactor })
.then(function(login) {
console.log('Logged in successfully. You can now publish widgets.');
})
.catch(function (error) {
console.log(error);
if (error.response.statusCode && error.response.statusCode === 428) {
prompt.start();
return prompt.get([
{
name: 'twofactor',
required: true
}
], function (err, result) {
if (!result) {
return;
}

login(email, password, result.twofactor);
});
}

console.log('Error:', error.response && error.response.body);
process.exit(1);
});
}
4 changes: 2 additions & 2 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function login (options) {
form: options
}, function (error, response, body) {
if (error) {
return reject(error);
return reject({ error, response, body });
}

if (response.statusCode !== 200) {
return reject(body);
return reject({ error, response, body });
}

const user = JSON.parse(body);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fliplet-cli",
"version": "3.7.6",
"version": "3.8.0",
"description": "Command line utility for creating and running components, themes and menus to be used on the Fliplet platform.",
"main": "fliplet.js",
"scripts": {
Expand Down

0 comments on commit c4664b2

Please sign in to comment.