Skip to content

Commit

Permalink
implement confirm password prompt and use it into wifi and system pas…
Browse files Browse the repository at this point in the history
…sword request
  • Loading branch information
hugomontero committed Feb 4, 2025
1 parent 6c219e2 commit 4139994
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 51 deletions.
61 changes: 10 additions & 51 deletions src/cmd/setup-tachyon.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,8 @@ Welcome to the Particle Tachyon setup! This interactive command:

async _userConfiguration() {
const systemPassword = await this._getSystemPassword();

const wifi = await this._getWifi();

const sshPublicKey = await this._getKeys();

return { systemPassword, wifi, sshPublicKey };
}

Expand All @@ -353,38 +350,10 @@ Welcome to the Particle Tachyon setup! This interactive command:
}

async _getSystemPassword() {
const questions = [
{
type: 'password',
name: 'password',
message: 'Password for the system account:',
validate: (value) => {
if (!value) {
return 'Enter a password for the root account';
}
return true;
}
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter the password for the root account:',
validate: (value) => {
if (!value) {
return 'You need to confirm the password';
}
return true;
}
}
];
const res = await this.ui.prompt(questions);

//check if the passwords match
if (res.password !== res.passwordConfirm) {
throw new Error('Passwords do not match. Please try again.');
}

return res.password;
return this.ui.promptPasswordWithConfirmation({
customMessage: 'Enter a password for the system account:',
customConfirmationMessage: 'Re-enter the password for the system account:'
});
}

async _getWifi() {
Expand All @@ -410,25 +379,15 @@ Welcome to the Particle Tachyon setup! This interactive command:
type: 'input',
name: 'ssid',
message: 'Enter your WiFi SSID:'
},
{
type: 'password',
name: 'password',
message: 'Enter your WiFi password:'
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter your WiFi password:'
},
}
];
const res = await this.ui.prompt(questions);
const { password } = await this.ui.promptPasswordWithConfirmation({
customMessage: 'Enter your WiFi password:',
customConfirmationMessage: 'Re-enter your WiFi password:'
});

if (res.password !== res.passwordConfirm) {
throw new Error('Passwords do not match. Please try again.');
}

return { ssid: res.ssid, password: res.password };
return { ssid: res.ssid, password };
}

async _getKeys() {
Expand Down
26 changes: 26 additions & 0 deletions src/lib/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ module.exports = class UI {
return inquirer.prompt(question);
}

async promptPasswordWithConfirmation({ customMessage, customConfirmationMessage } = {}) {
let unmatchedPassword = true;
let password;
const questions = [{
type: 'password',
name: 'requestedPassword',
message: customMessage || 'Enter your password:'
},
{
type: 'password',
name: 'confirmPassword',
message: customConfirmationMessage || 'Confirm your password:'
}];
while (unmatchedPassword) {
const { requestedPassword, confirmPassword } = await this.prompt(questions);
// Verify that the passwords match
if (requestedPassword !== confirmPassword) {
this.write('Passwords do not match. Please try again.');
} else {
password = requestedPassword;
unmatchedPassword = false;
}
}
return password;
}

createProgressBar() {
return new cliProgress.SingleBar({
format: '[{bar}] {percentage}% | {description}',
Expand Down

0 comments on commit 4139994

Please sign in to comment.