@@ -10,6 +10,15 @@ import {
1010 VerifyEmailQuery
1111} from '../../types' ;
1212
13+ /**
14+ * - Method: `POST`
15+ * - Endpoint: `/signup`
16+ * - Authenticated: `false`
17+ * - Id: `UserController.createUser`
18+ *
19+ * Description:
20+ * - Create a new user
21+ */
1322export const createUser : RequestHandler <
1423 { } ,
1524 PublicUserOrError ,
@@ -71,6 +80,15 @@ export const createUser: RequestHandler<
7180 }
7281} ;
7382
83+ /**
84+ * - Method: `GET`
85+ * - Endpoint: `/signup/duplicate_check`
86+ * - Authenticated: `false`
87+ * - Id: `UserController.duplicateUserCheck`
88+ *
89+ * Description:
90+ * - Check if a user with the same email or username already exists
91+ */
7492export const duplicateUserCheck : RequestHandler <
7593 { } ,
7694 { } ,
@@ -94,29 +112,15 @@ export const duplicateUserCheck: RequestHandler<
94112 } ) ;
95113} ;
96114
97- export const verifyEmail : RequestHandler < { } , { } , { } , VerifyEmailQuery > = async (
98- req ,
99- res
100- ) => {
101- const token = req . query . t ;
102- const user = await User . findOne ( {
103- verifiedToken : token ,
104- verifiedTokenExpires : { $gt : new Date ( ) }
105- } ) . exec ( ) ;
106- if ( ! user ) {
107- res . status ( 401 ) . json ( {
108- success : false ,
109- message : 'Token is invalid or has expired.'
110- } ) ;
111- return ;
112- }
113- user . verified = User . EmailConfirmation ( ) . Verified ;
114- user . verifiedToken = null ;
115- user . verifiedTokenExpires = null ;
116- await user . save ( ) ;
117- res . json ( { success : true } ) ;
118- } ;
119-
115+ /**
116+ * - Method: `POST`
117+ * - Endpoint: `/verify/send`
118+ * - Authenticated: `false`
119+ * - Id: `UserController.emailVerificationInitiate`
120+ *
121+ * Description:
122+ * - Send a Confirm Email email to verify that the user owns the specified email account
123+ */
120124export const emailVerificationInitiate : RequestHandler <
121125 { } ,
122126 PublicUserOrError
@@ -157,3 +161,35 @@ export const emailVerificationInitiate: RequestHandler<
157161 res . status ( 500 ) . json ( { error : err } ) ;
158162 }
159163} ;
164+
165+ /**
166+ * - Method: `GET`
167+ * - Endpoint: `/verify`
168+ * - Authenticated: `false`
169+ * - Id: `UserController.verifyEmail`
170+ *
171+ * Description:
172+ * - Used in the Confirm Email's link to verify a user's email is attached to their account
173+ */
174+ export const verifyEmail : RequestHandler < { } , { } , { } , VerifyEmailQuery > = async (
175+ req ,
176+ res
177+ ) => {
178+ const token = req . query . t ;
179+ const user = await User . findOne ( {
180+ verifiedToken : token ,
181+ verifiedTokenExpires : { $gt : new Date ( ) }
182+ } ) . exec ( ) ;
183+ if ( ! user ) {
184+ res . status ( 401 ) . json ( {
185+ success : false ,
186+ message : 'Token is invalid or has expired.'
187+ } ) ;
188+ return ;
189+ }
190+ user . verified = User . EmailConfirmation ( ) . Verified ;
191+ user . verifiedToken = null ;
192+ user . verifiedTokenExpires = null ;
193+ await user . save ( ) ;
194+ res . json ( { success : true } ) ;
195+ } ;
0 commit comments