@@ -22,38 +22,49 @@ import {
22
22
*/
23
23
export const signup = async ( req , res ) => {
24
24
console . log ( "signup requested" , req . body ) ;
25
- const { firstname, lastname, phone, address, username, password, about } =
26
- req . body ;
25
+ const { firstname, lastname, phone, username, userType } = req . body ;
27
26
const dBUserByEmail = await getDBUserByEmail ( { username : username } ) ;
28
27
if ( dBUserByEmail ) {
29
28
return res . status ( 401 ) . send ( { message : "User Already Exists" } ) ;
30
29
}
31
30
32
- let hashedPassword = await getHashedPassword ( password ) ;
33
31
const registerResult = await registerUser ( {
34
32
firstname : firstname ,
35
33
lastname : lastname ,
36
34
username : username ,
37
- password : hashedPassword ,
38
35
phone : phone ,
39
- address : address ,
40
- about : about ,
36
+ userType : userType ,
37
+ isActive : false ,
41
38
} ) ;
42
39
43
- var confirmationToken = await jwt . sign (
44
- { id : registerResult . insertedId . toString ( ) } ,
45
- process . env . SECRET_KEY
46
- ) ;
40
+ let resetToken = Crypto . randomBytes ( 16 ) . toString ( "hex" ) ;
41
+ let hashedResetToken = await getHashedPassword ( resetToken ) ;
42
+
43
+ let tokenUpdate = await insertToken ( { username : username } , hashedResetToken ) ;
44
+ if ( ! tokenUpdate ) {
45
+ return res . status ( 401 ) . send ( {
46
+ message : "Something went wront..Please try again later." ,
47
+ success : false ,
48
+ } ) ;
49
+ }
47
50
48
- const isInserted = await insertAccountConfirmationCode (
49
- { username : username } ,
50
- confirmationToken
51
+ console . log ( "inserted id is" , registerResult ) ;
52
+
53
+ if ( ! tokenUpdate ) {
54
+ return res . status ( 401 ) . send ( {
55
+ message : "Something went wront..Please try again later." ,
56
+ success : false ,
57
+ } ) ;
58
+ }
59
+
60
+ const mailsuccess = await sendPasswordResetMail (
61
+ username ,
62
+ hashedResetToken ,
63
+ registerResult . insertedId
51
64
) ;
52
- console . log ( "isInserted" , isInserted ) ;
53
- sendAccountVerificationMail ( username , confirmationToken , firstname ) ;
54
65
55
66
res . status ( 200 ) . send ( {
56
- message : "User was registered successfully! Please Verify Your Email! " ,
67
+ message : "User was registered successfully! " ,
57
68
success : true ,
58
69
} ) ;
59
70
} ;
@@ -98,13 +109,13 @@ export const login = async (req, res) => {
98
109
user : {
99
110
name : dBUserByEmail . firstname ,
100
111
email : dBUserByEmail . username ,
101
- userType : dBUserByEmail . role ,
102
- address : dBUserByEmail . address ,
112
+ userType : dBUserByEmail . userType ,
103
113
token : token ,
104
114
} ,
105
115
} ) ;
106
116
} ;
107
117
118
+ //TODO:-useThis fo
67E6
r user activation
108
119
export const forgotPassword = async ( req , res ) => {
109
120
const { email } = req . body ;
110
121
@@ -155,6 +166,7 @@ export const resetpassword = async (req, res) => {
155
166
const query = { token : token } ;
156
167
const updateQuery = { $set : { password : hashedPassword } } ;
157
168
const updatePasswordResult = await updatePassword ( query , updateQuery ) ;
169
+ const activateUser = await activatateUser ( token ) ;
158
170
159
171
// const deleteTokenResult = await deleteToken(token); TODO: remove this comment and delete below line
160
172
const deleteTokenResult = true ;
0 commit comments