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: email change improvements #132

Merged
merged 12 commits into from
Aug 20, 2021
Merged

Fix: email change improvements #132

merged 12 commits into from
Aug 20, 2021

Conversation

kangmingtay
Copy link
Member

@kangmingtay kangmingtay commented Jul 6, 2021

What kind of change does this PR introduce?

Addresses #60 and #78

What is the current behavior?

Email change verification is broken.

What is the new behavior?

Allows a user to change their email. Requires the user's jwt access token to call PUT /user.

For security reasons, we send out 2 emails when a user makes an update email request:

  1. Confirm email change email is sent to user's current email
  2. Confirm email change email is sent to user's new email

The user needs to log into both email accounts and verify by clicking both links.

Design

email_change_token_current: Keeps track of token sent to current email
email_change_token_new: Keeps track of token sent to new email
email_change_confirm_status: Keeps track of the number of verified email (0, 1, 2)

Additional context

Adds /verify?type=email_change to handle email change verification logic.

@kangmingtay kangmingtay requested a review from awalias July 6, 2021 05:16
Comment on lines +139 to +155
go func(e, t string) {
data := map[string]interface{}{
"SiteURL": m.Config.SiteURL,
"ConfirmationURL": url,
"Email": user.GetEmail(),
"NewEmail": user.EmailChange,
"Token": t,
"Data": user.UserMetaData,
}
errors <- m.Mailer.Mail(
e,
string(withDefault(m.Config.Mailer.Subjects.EmailChange, "Confirm Email Change")),
m.Config.Mailer.Templates.EmailChange,
defaultEmailChangeMail,
data,
)
}(email, token)
Copy link
Member Author

Choose a reason for hiding this comment

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

Send emails concurrently via goroutines since they don't have to be sequential

Comment on lines +158 to +165
for i := 0; i < len(tokens); i++ {
e := <-errors
if e != nil {
return e
}
}

return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

check if any of the goroutines experienced an error sending the email

@kangmingtay kangmingtay requested a review from thebengeu July 30, 2021 19:07
@kangmingtay kangmingtay self-assigned this Jul 30, 2021
@kangmingtay kangmingtay added the enhancement New feature or request label Jul 30, 2021
@kangmingtay kangmingtay requested a review from inian July 31, 2021 04:33
models/user.go Outdated
@@ -341,6 +352,11 @@ func FindUserByRecoveryToken(tx *storage.Connection, token string) (*User, error
return findUser(tx, "recovery_token = ?", token)
}

// FindUserByRecoveryToken finds a user with the matching recovery token.
Copy link
Member

Choose a reason for hiding this comment

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

Update comment?


DO $$
BEGIN
IF NOT EXISTS(SELECT *
Copy link
Member

Choose a reason for hiding this comment

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

Should this be IF EXISTS?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah you're right, i forgot to remove my docker volume after making the change manually so i thought the migration worked 😅

THEN
ALTER TABLE "auth"."users" RENAME COLUMN "email_change_token" TO "email_change_token_new";
END IF;
END $$;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: add newline at end of file?

@kangmingtay kangmingtay merged commit 9b955cb into master Aug 20, 2021
@kangmingtay kangmingtay deleted the pr-email-change branch August 20, 2021 07:44
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.0.11 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants