-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-[167190531]: Implement User Reset Password Via Email
- create route to request and send password reset link to user email - create route to reset password - add valiadations for user inputs - add model,unit and integration tests - document feature with swagger [Delivers #167190531]
- Loading branch information
Showing
18 changed files
with
679 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
server/database/migrations/20190807120440-create-reset-password-token.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('ResetPasswords', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
allowNull: false, | ||
type: Sequelize.INTEGER, | ||
onDelete: 'CASCADE', | ||
references: { | ||
model: 'Users', | ||
key: 'id' | ||
} | ||
}, | ||
token: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: (queryInterface, Sequelize) => queryInterface.dropTable('ResetPasswords') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default (sequelize, DataTypes) => { | ||
const ResetPassword = sequelize.define('ResetPassword', { | ||
userId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
token: { | ||
type: DataTypes.STRING, | ||
unique: true, | ||
allowNull: false | ||
} | ||
}); | ||
return ResetPassword; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import jwt from 'jsonwebtoken'; | ||
|
||
/** | ||
* | ||
* | ||
* | ||
* @param {string} token jwt token | ||
* @returns {integer} id of the user | ||
*/ | ||
const verifyResetToken = async (token) => { | ||
try { | ||
const { id } = await jwt.verify(token, process.env.JWT_KEY); | ||
return id; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default verifyResetToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { verifyToken, getSessionFromToken } from './verifyToken'; | ||
import validateUserSignup from './userValidation'; | ||
import validate from './userValidation'; | ||
|
||
const middlewares = { verifyToken, validateUserSignup, getSessionFromToken }; | ||
const middlewares = { verifyToken, validate, getSessionFromToken }; | ||
|
||
export default middlewares; |
Oops, something went wrong.