Skip to content

Add support for resending verification email in case of expired token #3617

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

Merged

Conversation

cmmills91
Copy link
Contributor

  • Defines new public API route /apps/:appId/resend_verification_email that will generate a new email verification link and email for a user identified by username in POST body

  • Add default template and url support for invalid_verification_link, link_send_success, and link_send_fail pages. The invalid_verification_link page includes a button that allows the user to generate a new verification email if their current token has expired, using the new public API route

  • All three pages have default html that will be functional "out of the box", but they can be customized in the customPages object. The custom page for invalidVerificationLink needs to handle the extraction of the username and appId from the url and the POST to generate the new link (this requires javascript)

  • Clicking a link for an email that has already been verified now routes to the emailVerifySuccess page instead of the invalidLink page

Cody Mills and others added 3 commits March 10, 2017 15:23
…that will generate a new email verification link and email for a user identified by username in POST body

-Add template and url support for invalidVerificationLink, linkSendSuccess, and linkSendFail pages. The invalidVerificationLink pages includes a button that allows the user to generate a new verification email if their current token has expired, using the new public API route
-All three pages have default html that will be functional out of the box, but they can be customized in the customPages object. The custom page for invalidVerificationLink needs to handle the extraction of the username and appId from the url and the POST to generate the new link (this requires javascript)
-Clicking a link for an email that has already been verified now routes to the emailVerifySuccess page instead of the invalidLink page
Implementation for allowing link resend when it's invalid.
@cmmills91 cmmills91 changed the title Support for resending verification email in case of expired token Add support for resending verification email in case of expired token Mar 13, 2017
@flovilmart
Copy link
Contributor

@cmmills91 Thanks for the great pull request! Love that feature! Can you address the issues with the lint?

> [email protected] lint /home/travis/build/ParsePlatform/parse-server
> eslint --cache ./
/home/travis/build/ParsePlatform/parse-server/src/Controllers/UserController.js
   68:8   error  Trailing spaces not allowed      no-trailing-spaces
  151:84  error  'res' is defined but never used  no-unused-vars

you can run locally with npm test or npm run lint

I'll start the review after!

@facebook-github-bot
Copy link

@cmmills91 updated the pull request - view changes

@cmmills91
Copy link
Contributor Author

Should I adjust unit tests as well? Looks like they're making CI tests fail

@flovilmart
Copy link
Contributor

Yup seems like some tests are failing now: https://travis-ci.org/ParsePlatform/parse-server/jobs/210725165#L838

@facebook-github-bot
Copy link

@cmmills91 updated the pull request - view changes

1 similar comment
@facebook-github-bot
Copy link

@cmmills91 updated the pull request - view changes

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<!-- This page is displayed when someone navigates to a verify email or reset password link
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we should keep those comments, when serving the files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean removing the comments from the html file entirely or is there some kind of general solution the can remove comments from the file before being sent back?

The existing invalid_link.html file already has similar set of comments (in fact, the exact same comments that appear in these files since I just copied over the contents of invalid_link and made a few alterations 😅 )

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to edit the comments on the pages to be more relevant though

@@ -359,7 +359,7 @@ describe("Email Verification Token Expiration: ", () => {
followRedirect: false,
}, (error, response) => {
expect(response.statusCode).toEqual(302);
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html');
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity');
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we should change that page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes more sense to direct a user that page than the invalid_link or invalid_verification_link page. I made the change based on clicking on a few verification links in my inbox (that I had already verified) and more than half of them did showed the success page (small sample size though)

@@ -134,6 +141,19 @@ export class UserController extends AdaptableController {
});
}

resendVerificationEmail(username) {
var self = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for self, if you're using arrow functions.

throw undefined;
}
self.setEmailVerifyToken(aUser);
return self.config.database.update('_User', {username}, aUser).then(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

replace function() by () => and remove self

if (req.query.username && req.params.appId) {
return Promise.resolve({
status: 302,
location: req.config.invalidVerificationLinkURL + '?username=' + req.query.username + '&appId=' + req.params.appId
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use a template string?

@@ -140,6 +179,10 @@ export class PublicAPIRouter extends PromiseRouter {
req => { this.setConfig(req) },
req => { return this.verifyEmail(req); });

this.route('POST', '/apps/:appId/resend_verification_email',
req => {this.setConfig(req) },
Copy link
Contributor

Choose a reason for hiding this comment

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

space beween { and this 

Copy link
Contributor

Choose a reason for hiding this comment

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

add ; after this.setConfig(req)

return this.config.database.update('_User', query, updateFields).then((document) => {
if (!document) {
throw undefined;
var self = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove self, and replace function() by () => (arrow functions)

@flovilmart
Copy link
Contributor

I just had a few nits here and there, otherwise that looks great!

…emplate to construct location for invalidVerificationLink page, syntax fixes
@facebook-github-bot
Copy link

@cmmills91 updated the pull request - view changes

@facebook-github-bot
Copy link

@cmmills91 updated the pull request - view changes

<!-- This page is displayed when someone navigates to a verify email link with an invalid
security token and requests a link resend. This page is displayed when the username from
the original link is invalid or if the email of that user has already been verfieid when
the resend request is made
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo 'verified'

@flovilmart flovilmart merged commit 22ba398 into parse-community:master May 10, 2017
@flovilmart
Copy link
Contributor

@cmmills91 sorry for the delay to get that one in, thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants