Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1182 #1188

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function _checkForDuplicateEmail(sessionUser, email) {

async function add(req, res) {
const sessionUser = await _requireSessionUser(req);
const email = req.body.email;
const email = req.body.email.toLowerCase();
if (!email || !isemail.validate(email)) {
throw new FluentError("user-add-invalid-email");
}
Expand Down Expand Up @@ -135,8 +135,9 @@ async function add(req, res) {
res.redirect("/user/preferences");
}

async function bundleVerifiedEmails(email, emailSha1, ifPrimary, id, verificationStatus, allBreaches) {
const foundBreaches = await HIBP.getBreachesForEmail(emailSha1, allBreaches, true);
async function bundleVerifiedEmails(email, ifPrimary, id, verificationStatus, allBreaches) {
const lowerCaseEmailSha = sha1(email.toLowerCase());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is emailSha1 now unused?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it is!

const foundBreaches = await HIBP.getBreachesForEmail(lowerCaseEmailSha, allBreaches, true);

const emailEntry = {
"email": email,
Expand All @@ -153,10 +154,10 @@ async function getAllEmailsAndBreaches(user, allBreaches) {
const monitoredEmails = await DB.getUserEmails(user.id);
let verifiedEmails = [];
const unverifiedEmails = [];
verifiedEmails.push(await bundleVerifiedEmails(user.primary_email, user.primary_sha1, true, user.id, user.primary_verified, allBreaches));
verifiedEmails.push(await bundleVerifiedEmails(user.primary_email, true, user.id, user.primary_verified, allBreaches));
for (const email of monitoredEmails) {
if (email.verified) {
const formattedEmail = await bundleVerifiedEmails(email.email, email.sha1, false, email.id, email.verified, allBreaches);
const formattedEmail = await bundleVerifiedEmails(email.email, false, email.id, email.verified, allBreaches);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking observation ...

This function call signature reminds me I've been wanting to go thru our code-base and use JS options objects in most of our functions.

verifiedEmails.push(formattedEmail);
} else {
unverifiedEmails.push(email);
Expand Down