File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ const moongoose = require('mongoose');
2
2
const validator = require ( 'validator' ) ;
3
3
const bcrypt = require ( 'bcryptjs' ) ;
4
4
const jwt = require ( 'jsonwebtoken' ) ;
5
+ const crypto = require ( 'crypto' ) ;
5
6
6
7
const userSchema = new moongoose . Schema ( {
7
8
name : {
@@ -63,4 +64,23 @@ userSchema.methods.getJwtToken = function () {
63
64
} ) ;
64
65
} ;
65
66
67
+ // generate password reset token
68
+
69
+ userSchema . methods . getResetPasswordToken = function ( ) {
70
+ // generate token
71
+
72
+ const resetToken = crypto . randomBytes ( 20 ) . toString ( 'hex' ) ;
73
+
74
+ // Hash it and set to resetPasswordToken
75
+ this . resetPasswordToken = crypto
76
+ . createHash ( 'sha256' )
77
+ . update ( resetToken )
78
+ . digest ( 'hex' ) ;
79
+
80
+ // Set token Expire Time
81
+ this . resetPasswordExpire = Date . now ( ) + 30 * 60 * 1000 ;
82
+
83
+ return resetToken
84
+ } ;
85
+
66
86
module . exports = moongoose . model ( 'user' , userSchema ) ;
You can’t perform that action at this time.
0 commit comments