|
|
|
@ -52,37 +52,46 @@ const getViews = screen => {
|
|
|
|
|
});
|
|
|
|
|
const { form, text, button, textbox, checkbox, flexContainer, table } = helper(screen);
|
|
|
|
|
return {
|
|
|
|
|
disclaimer: () => new Promise(resolve => {
|
|
|
|
|
disclaimer: () => new Promise((resolve, reject) => {
|
|
|
|
|
const { name, version, description, homepage, author, license } = require('../../package');
|
|
|
|
|
const disclaimerForm = form();
|
|
|
|
|
text({ content: `${name} v${version} | ${description}\n\nBy ${author.name} | ${homepage}\n\nDistributed under the ${license} licence.` });
|
|
|
|
|
let n = 6;
|
|
|
|
|
const submitButton = button({ top: n, content: 'Proceed' }, undefined, disclaimerForm);
|
|
|
|
|
text({ top: n + 4, content: 'Quit to abort.' });
|
|
|
|
|
const actions = flexContainer({ top: 6 }, disclaimerForm);
|
|
|
|
|
const submitButton = button({ content: 'Proceed' }, undefined, actions);
|
|
|
|
|
button({ content: 'Cancel' }, { color: 'gray' }, actions).on('press', reject);
|
|
|
|
|
disclaimerForm.on('submit', () => resolve());
|
|
|
|
|
submitButton.on('press', () => disclaimerForm.submit());
|
|
|
|
|
screen.render();
|
|
|
|
|
submitButton.focus();
|
|
|
|
|
}),
|
|
|
|
|
wrongPassword: () => {
|
|
|
|
|
wrongPassword: quit => {
|
|
|
|
|
text(
|
|
|
|
|
{ content: '[!] Wrong password.\nPlease quit and try again.' },
|
|
|
|
|
{ color: 'red', borders: true }
|
|
|
|
|
);
|
|
|
|
|
const quitButton = button({ top: 5, content: 'Quit' });
|
|
|
|
|
quitButton.on('press', quit);
|
|
|
|
|
quitButton.focus();
|
|
|
|
|
screen.render();
|
|
|
|
|
},
|
|
|
|
|
pwnedPassword: () => {
|
|
|
|
|
pwnedPassword: quit => {
|
|
|
|
|
text(
|
|
|
|
|
{ content: '[!] Your password has been breached.\nSee https://haveibeenpwned.com/Passwords for more details.\nPlease quit and try again.' },
|
|
|
|
|
{ color: 'red', borders: true }
|
|
|
|
|
);
|
|
|
|
|
const quitButton = button({ top: 5, content: 'Quit' });
|
|
|
|
|
quitButton.on('press', quit);
|
|
|
|
|
quitButton.focus();
|
|
|
|
|
screen.render();
|
|
|
|
|
},
|
|
|
|
|
invalidUsername: () => {
|
|
|
|
|
invalidUsername: quit => {
|
|
|
|
|
text(
|
|
|
|
|
{ content: '[!] Your username is invalid.\nOnly alphanumeric characters are allowed.\nPlease quit and try again.' },
|
|
|
|
|
{ color: 'red', borders: true }
|
|
|
|
|
);
|
|
|
|
|
const quitButton = button({ top: 5, content: 'Quit' });
|
|
|
|
|
quitButton.on('press', quit);
|
|
|
|
|
quitButton.focus();
|
|
|
|
|
screen.render();
|
|
|
|
|
},
|
|
|
|
|
loginOtp: (isCancellable, callback) => {
|
|
|
|
@ -173,6 +182,8 @@ const getViews = screen => {
|
|
|
|
|
.on('press', () => callback({ action: 'edit-userpass' }));
|
|
|
|
|
button({ content: 'Delete account' }, undefined, mainActionsFormContainer)
|
|
|
|
|
.on('press', () => callback({ action: 'delete-account' }));
|
|
|
|
|
button({ content: 'Quit' }, undefined, mainActionsFormContainer)
|
|
|
|
|
.on('press', () => callback({ action: 'quit' }));
|
|
|
|
|
let selectedHost;
|
|
|
|
|
const tableHeight = Math.floor(screen.height / 4);
|
|
|
|
|
const hostsTable = table({
|
|
|
|
@ -420,7 +431,7 @@ const getViews = screen => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getControllers = stream => {
|
|
|
|
|
const getControllers = (stream, end) => {
|
|
|
|
|
let screen, views;
|
|
|
|
|
const init = () => {
|
|
|
|
|
screen = getScreen(stream);
|
|
|
|
@ -449,7 +460,12 @@ const getControllers = stream => {
|
|
|
|
|
if(error.message === 'WRONG_USERNAME'){
|
|
|
|
|
try {
|
|
|
|
|
let isConfirmed = false;
|
|
|
|
|
await views.disclaimer();
|
|
|
|
|
try {
|
|
|
|
|
await views.disclaimer();
|
|
|
|
|
}
|
|
|
|
|
catch(_){
|
|
|
|
|
return end();
|
|
|
|
|
}
|
|
|
|
|
const user = await account.register(username, password);
|
|
|
|
|
views.register({ username }, async ({ repeatPassword, passwordMismatchError, enableOtp }) => {
|
|
|
|
|
if(repeatPassword !== password) return passwordMismatchError();
|
|
|
|
@ -473,13 +489,13 @@ const getControllers = stream => {
|
|
|
|
|
}
|
|
|
|
|
catch(error){
|
|
|
|
|
if(error.message === 'PWNED_PASSWORD')
|
|
|
|
|
views.pwnedPassword();
|
|
|
|
|
views.pwnedPassword(end);
|
|
|
|
|
else if(error.message === 'INVALID_USERNAME')
|
|
|
|
|
views.invalidUsername();
|
|
|
|
|
views.invalidUsername(end);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(error.message === 'WRONG_PASSWORD')
|
|
|
|
|
views.wrongPassword();
|
|
|
|
|
views.wrongPassword(end);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
}),
|
|
|
|
@ -593,6 +609,7 @@ const getControllers = stream => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case 'quit': end();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -600,9 +617,9 @@ const getControllers = stream => {
|
|
|
|
|
return _controllers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = async (session, username, password) => {
|
|
|
|
|
module.exports = async (session, username, password, end) => {
|
|
|
|
|
const stream = await getStream(session);
|
|
|
|
|
const controllers = getControllers(stream);
|
|
|
|
|
const controllers = getControllers(stream, end);
|
|
|
|
|
const user = await controllers.auth(username, password);
|
|
|
|
|
controllers.main(user);
|
|
|
|
|
};
|
|
|
|
|