Skip to content

Commit

Permalink
Confirm receiving account name on init
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroCB committed Jul 21, 2020
1 parent 20a750d commit 3e061d8
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ can be the same account, probably yours, or you can create a dummy sender \
account).\n\nBy default, these credentials will not be stored for security \
reasons, but the session token identifying your login will be stored at \
${chalk.yellow(tools.getConfigDir())} (to change this, set your \
${chalk.grey("XDG_CONFIG_HOME")}).`);
${chalk.grey("XDG_CONFIG_HOME")} environment variable).`);

const sendEmail = rl.questionEMail("Sender account email: ");
const sendPass = rl.question("Sender account password: ", tools.passOpts);
Expand Down Expand Up @@ -74,24 +74,29 @@ function storePrefs(sendEmail, sendPass, recvEmail, recvPass, shouldStore, recvA
const recvId = recvApi.getCurrentUserID();
const sendSession = sendApi.getAppState();

const config = {
"recipient": recvId,
"appState": sendSession
}

if (shouldStore) {
config["email"] = sendEmail;
config["password"] = sendPass;
}

const configPath = tools.getConfigDir();
if (!fs.existsSync(configPath)) {
fs.mkdirSync(configPath);
}

console.log(`${chalk.green("Login successful.")} Storing your session in ${chalk.yellow(tools.getConfigDir())}...`);
fs.writeFileSync(tools.getConfigPath(), JSON.stringify(config));
callback(null, sendApi);
recvApi.getUserInfo(recvId, (err, info) => {
const name = !err ? info[recvId].name : null;
const nameStr = name ? `Notifications will be sent to ${chalk.blue(name)}. ` : "";

const config = {
"recipient": recvId,
"appState": sendSession
}

if (shouldStore) {
config["email"] = sendEmail;
config["password"] = sendPass;
}

const configPath = tools.getConfigDir();
if (!fs.existsSync(configPath)) {
fs.mkdirSync(configPath);
}

console.log(`${chalk.green("Login successful.")} ${nameStr}Storing your session in ${chalk.yellow(tools.getConfigDir())}...`);
fs.writeFileSync(tools.getConfigPath(), JSON.stringify(config));
callback(null, sendApi);
});
});
});
}
Expand Down

0 comments on commit 3e061d8

Please sign in to comment.