-
Notifications
You must be signed in to change notification settings - Fork 1
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
#187419058 Reset password via email #17
Conversation
src/controllers/resetPasswort.ts
Outdated
@@ -0,0 +1,99 @@ | |||
import { Request, Response, NextFunction } from 'express'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
src/controllers/resetPasswort.ts
Outdated
}; | ||
|
||
|
||
export const resetPassword = async (req: Request, res: Response, next: NextFunction) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function resetPassword
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
src/helpers/security.helpers.ts
Outdated
|
||
export const generateAccessToken = (userData: TokenData) => { | ||
const token = jwt.sign(userData, ACCESS_TOKEN_SECRET as string, { | ||
expiresIn: "1d", | ||
}); | ||
return token; | ||
}; | ||
export const generatePasswordResetToken = (userData1: resetTokenData) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
3bba3d8
to
d0f87db
Compare
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
src/controllers/resetPasswort.ts
Outdated
} | ||
}; | ||
|
||
export const resetPassword = async (req: Request, res: Response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function resetPassword
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
src/middlewares/user.middleware.ts
Outdated
try { | ||
if (req.body) { | ||
const { error } = userValidate(req.body); | ||
if (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/middlewares/user.middleware.ts
Outdated
error.details[0].message.replace(/\"/g, "") | ||
) | ||
); | ||
if (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/documention/user/index.ts
Outdated
// security: [{ JWT: [] }], | ||
summary: "Request password reset", | ||
parameters: [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
}, | ||
description: "The reset password token", | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
643520c
to
fd3ef65
Compare
|
||
resetToken = body.token; | ||
}); | ||
it("it should return 404 when user requesting reset is not found in database", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/__test__/users.test.ts
Outdated
|
||
expect(body.message).toEqual("User not found"); | ||
}); | ||
it("it should return 200 when email is sent", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
expect(401); | ||
expect(body.status).toStrictEqual("UNAUTHORIZED"); | ||
expect(body.message).toStrictEqual("Already logged out"); | ||
it("should return 400 when no token is provided", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/documention/user/index.ts
Outdated
// security: [{ JWT: [] }], | ||
summary: "Request password reset", | ||
parameters: [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/documention/user/index.ts
Outdated
}, | ||
description: "The reset password token", | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
6a007d1
to
fda81e4
Compare
2cd8400
to
414d414
Compare
@@ -0,0 +1,33 @@ | |||
import { DataTypes, Model } from "sequelize"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
@@ -0,0 +1,18 @@ | |||
import Joi from "joi"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
@@ -0,0 +1,14 @@ | |||
import Joi from "joi"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
5678f04
to
4cabfce
Compare
|
||
next(); | ||
}; | ||
const isPassword = (req: Request, res: Response, next: NextFunction) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
@@ -45,7 +47,42 @@ const logInValidated = (req: Request, res: Response, next: NextFunction) => { | |||
next(); | |||
}; | |||
|
|||
const resetValidated = (req: Request, res: Response, next: NextFunction) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
} | ||
}; | ||
|
||
export const resetPasswort = async (req: Request, res: Response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function resetPasswort
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
import Joi from "joi"; | ||
|
||
const ResetPasswordValidation = Joi.object({ | ||
email: Joi.string().required().email().messages({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
// security: [{ JWT: [] }], | ||
summary: "Request password reset", | ||
parameters: [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
b40cf2a
to
92ae79f
Compare
92ae79f
to
4ba44f6
Compare
.expect(400); | ||
}); | ||
|
||
it("it should return 200 when password reset successfully", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
.expect(404); | ||
}); | ||
|
||
it("it should return 400 when new password is the same to old password", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
src/__test__/users.test.ts
Outdated
.send(newPasswordBody) | ||
.expect(200); | ||
}); | ||
it("it should return 400 no decoded token is found", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
.expect(400); | ||
}); | ||
|
||
it("it should return 400 when invalid link is provided", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
6515900
to
50dfa1a
Compare
sendEmail: jest.fn(), | ||
})); | ||
|
||
it("should send an email with the correct mailOptions", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
sendEmail: jest.fn(), | ||
})); | ||
|
||
it("should send an email with the correct mailOptions", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
50dfa1a
to
145cb1d
Compare
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: Unexpected token up
@@ -0,0 +1,35 @@ | |||
import nodemailer from "nodemailer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
// security: [{ JWT: [] }], | ||
summary: "Request password reset", | ||
parameters: [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
}, | ||
description: "The reset password token", | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
- User who forgot password can request resetting it - Sending reset-password email containing link along with token to reset password - Reset password using the provided token - Token is used only once [Delivers #187419058]
145cb1d
to
f011810
Compare
Code Climate has analyzed commit f011810 and detected 11 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 94.0% (60% is the threshold). This pull request will bring the total coverage in the repository to 91.0% (1.5% change). View more on Code Climate. |
What does this PR do?
Description of Task to be completed?
How should this be manually tested?
npm install
.env
file as they appear in .env example filenpm run dev
api/v1/users/register
/api/v1/users/forgot-password
/api/v1/users/reset-password/:token
and provide a new password in the body/api/v1/users/login
What are the relevant pivotal tracker/Trello stories?
#187419058