Prettied up UI for password resets. Now to move on to email component.
This commit is contained in:
parent
ed698f40c7
commit
3671b43789
5 changed files with 51 additions and 18 deletions
|
|
@ -41,7 +41,7 @@ module.exports.post = async function(req, res){
|
|||
}
|
||||
|
||||
//Generate the password reset link
|
||||
const requestDB = await passwordResetModel.generateResetToken(userDB);
|
||||
const requestDB = await passwordResetModel.create({user: userDB._id});
|
||||
|
||||
//send successful response
|
||||
res.status(200);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ const passwordResetSchema = new mongoose.Schema({
|
|||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true
|
||||
required: true,
|
||||
//Use a cryptographically secure algorythm to create a random hex string from 16 bytes as our reset token
|
||||
default: ()=>{return crypto.randomBytes(16).toString('hex')}
|
||||
},
|
||||
date: {
|
||||
|
||||
|
|
@ -47,21 +49,6 @@ const passwordResetSchema = new mongoose.Schema({
|
|||
});
|
||||
|
||||
//statics
|
||||
passwordResetSchema.statics.generateResetToken = async function(userDB){
|
||||
//Use a cryptographically secure algorythm to create a random hex string from 16 bytes as our reset token
|
||||
const token = crypto.randomBytes(16).toString('hex');
|
||||
|
||||
//Create request object
|
||||
const request = {
|
||||
user: userDB._id,
|
||||
token,
|
||||
date: new Date()
|
||||
}
|
||||
|
||||
//Create the request entry in the DB and return the newly created record
|
||||
return await this.create(request);
|
||||
}
|
||||
|
||||
passwordResetSchema.statics.processExpiredRequests = async function(){
|
||||
//Pull all requests from the DB
|
||||
const requestDB = await this.find({});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue