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

#165412914 add reset password endpoint #29

Merged
merged 1 commit into from
May 17, 2019

Conversation

luc-tuyishime
Copy link
Contributor

What does this PR do?

  • Have Create and Update on ressources endpoint for reset password in express REST API

Description of Task to be completed?

Have the following endpoints working

  • POST api/v1/auth/reset/

  • UPDATE api/v1/auth/:token

How should this be manually tested?

  • Using Postman for testing all the endpoints above

Any background context you want to provide?

  • None

What are the relevant pivotal tracker stories?

  • (#165412914)[https://www.pivotaltracker.com/story/show/165412914]

Screenshots (if appropriate)

  • None

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 13 times, most recently from f1f2de6 to eb577a5 Compare May 9, 2019 10:31
@@ -0,0 +1,14 @@
import status from '../config/status';

const errorCatcher = controller => async (req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@luc-tuyishime give the function a more appropriate name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes applied

});
}
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const isSent = process.env.NODE_ENV === 'test' ? null : await sgMail.send(helper.sendgridMailTemplate.resetPassword(email, 'noreply@authersheaven.com'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we agreed on a sendEmail helper that anyone can use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes applied

Copy link
Contributor

@e-liyai e-liyai left a comment

Choose a reason for hiding this comment

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

requested changes

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 3 times, most recently from 055c1e1 to a44f74c Compare May 10, 2019 09:04
});
}

await helper.sendMail(email); // send mail
Copy link
Contributor

Choose a reason for hiding this comment

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

@luc-tuyishime this should be wrapped by an error handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have an async handler middleware that catches errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

how has it been connected to this sendMail function?

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 call the middleware in the routes.
the path to the route: routes/auth/local.js

Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@@ -0,0 +1,14 @@
import status from '../config/status';

const errorHandler = controller => async (req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function name has not been renamed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes applied

* @param {object} condition where to update
* @returns {boolean} return true when successfuly updated otherwise false
*/
export default async (what = {}, condition = {}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the variable name what

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's what we want to update like a password.

Copy link
Contributor

Choose a reason for hiding this comment

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

give it a more appropriate name. what is not properly descriptive.

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 have renamed the what name to value.

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 3 times, most recently from c139442 to a537c7a Compare May 11, 2019 16:23
subject: 'Password Reset',
html: `<p>You are receiving this because you (or someone else) have requested the reset of the password,<br>
Click on the reset link bellow to complete the process<br>
<a href='http://localhost:3000/api/v1/auth/reset/${tokenGenerator({ email: to }, { expiresIn: '2h' })}' target='_blank'>Reset Password</a></p>`
Copy link
Contributor

Choose a reason for hiding this comment

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

@luc-tuyishime, I propose the redirect URL be defined in an .env file so that we don't have to change this file in case we want to use another URL, so it maybe something like APP_URL and the you use it this file

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense. Let's do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes applied

passwordTwo: 'newpassworda',
};

const newUser = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest you use the helper that I defined to generate fake user accounts

Copy link
Contributor

Choose a reason for hiding this comment

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

there shouldn't be static declaration objects here, create files to generate this data or reuse what is already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes applied

subject: 'Password Reset',
html: `<p>You are receiving this because you (or someone else) have requested the reset of the password,<br>
Click on the reset link bellow to complete the process<br>
<a href='http://localhost:3000/api/v1/auth/reset/${tokenGenerator({ email: to }, { expiresIn: '2h' })}' target='_blank'>Reset Password</a></p>`
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense. Let's do that

passwordTwo: 'newpassworda',
};

const newUser = {
Copy link
Contributor

Choose a reason for hiding this comment

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

there shouldn't be static declaration objects here, create files to generate this data or reuse what is already there.

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 2 times, most recently from 41c185c to d8a6cd7 Compare May 13, 2019 18:42
@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 2 times, most recently from aa7e1b5 to db0e3c4 Compare May 13, 2019 19:17
Copy link
Contributor

@sengayire sengayire left a comment

Choose a reason for hiding this comment

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

rebase your PR with a new commit from develop

@luc-tuyishime
Copy link
Contributor Author

rebase your PR with a new commit from develop

ok thanks

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch 5 times, most recently from 96ad798 to 0f62d24 Compare May 15, 2019 12:34
* @export
* @param {object} req
* @param {object} res
* @param {void} next
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a good practice to put descriptive JSDOC comments

@@ -0,0 +1,32 @@
import db from '../models';
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to use the same file naming convention.

{ expiresIn: '2h' }
)}' target='_blank'>Reset Password</a></p>`
})
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better you create a reusable mail template.
So that other team member can use this helper to send emails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This template is already a reusable template, you can use it to send emails.

@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch from 0f62d24 to 75ce816 Compare May 16, 2019 11:41
#165412912 validate user input on signup
@luc-tuyishime luc-tuyishime force-pushed the feature/be-reset-password-165412914 branch from 75ce816 to e008dcd Compare May 16, 2019 11:48
@denislohan denislohan dismissed e-liyai’s stale review May 17, 2019 08:16

the reviewer on leave

@denislohan denislohan merged commit 54c93d4 into develop May 17, 2019
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.

None yet

7 participants