@@ -2,13 +2,12 @@ import async from "async";
2
2
import crypto from "crypto" ;
3
3
import nodemailer from "nodemailer" ;
4
4
import passport from "passport" ;
5
- import { AuthToken , User , UserDocument } from "../models/User" ;
6
- import { Request , Response } from "express" ;
7
- import { IVerifyOptions } from "passport-local" ;
8
- import { WriteError } from "mongodb" ;
9
- import { check , sanitize , validationResult } from "express-validator" ;
5
+ import { User , UserDocument , AuthToken } from "../models/User" ;
6
+ import { Request , Response , NextFunction } from "express" ;
7
+ import { IVerifyOptions } from "passport-local" ;
8
+ import { WriteError } from "mongodb" ;
9
+ import { check , sanitize , validationResult } from "express-validator" ;
10
10
import "../config/passport" ;
11
- import { genericExpressMethod } from "express-request-with-user" ;
12
11
13
12
/**
14
13
* GET /login
@@ -27,8 +26,7 @@ export const getLogin = (req: Request, res: Response) => {
27
26
* POST /login
28
27
* Sign in using email and password.
29
28
*/
30
-
31
- export const postLogin : genericExpressMethod = ( req , res , next ) => {
29
+ export const postLogin = ( req : Request , res : Response , next : NextFunction ) => {
32
30
check ( "email" , "Email is not valid" ) . isEmail ( ) ;
33
31
check ( "password" , "Password cannot be blank" ) . isLength ( { min : 1 } ) ;
34
32
// eslint-disable-next-line @typescript-eslint/camelcase
@@ -81,7 +79,7 @@ export const getSignup = (req: Request, res: Response) => {
81
79
* POST /signup
82
80
* Create a new local account.
83
81
*/
84
- export const postSignup : genericExpressMethod = ( req , res , next ) => {
82
+ export const postSignup = ( req : Request , res : Response , next : NextFunction ) => {
85
83
check ( "email" , "Email is not valid" ) . isEmail ( ) ;
86
84
check ( "password" , "Password must be at least 4 characters long" ) . isLength ( { min : 4 } ) ;
87
85
check ( "confirmPassword" , "Passwords do not match" ) . equals ( req . body . password ) ;
@@ -132,7 +130,7 @@ export const getAccount = (req: Request, res: Response) => {
132
130
* POST /account/profile
133
131
* Update profile information.
134
132
*/
135
- export const postUpdateProfile : genericExpressMethod = ( req , res , next ) => {
133
+ export const postUpdateProfile = ( req : Request , res : Response , next : NextFunction ) => {
136
134
check ( "email" , "Please enter a valid email address." ) . isEmail ( ) ;
137
135
// eslint-disable-next-line @typescript-eslint/camelcase
138
136
sanitize ( "email" ) . normalizeEmail ( { gmail_remove_dots : false } ) ;
@@ -144,7 +142,6 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => {
144
142
return res . redirect ( "/account" ) ;
145
143
}
146
144
147
- // const user = req.user as UserDocument;
148
145
User . findById ( req . user . id , ( err , user ) => {
149
146
if ( err ) { return next ( err ) ; }
150
147
user . email = req . body . email || "" ;
@@ -170,7 +167,7 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => {
170
167
* POST /account/password
171
168
* Update current password.
172
169
*/
173
- export const postUpdatePassword : genericExpressMethod = ( req , res , next ) => {
170
+ export const postUpdatePassword = ( req : Request , res : Response , next : NextFunction ) => {
174
171
check ( "password" , "Password must be at least 4 characters long" ) . isLength ( { min : 4 } ) ;
175
172
check ( "confirmPassword" , "Passwords do not match" ) . equals ( req . body . password ) ;
176
173
@@ -181,7 +178,6 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => {
181
178
return res . redirect ( "/account" ) ;
182
179
}
183
180
184
- // const user = req.user as UserDocument;
185
181
User . findById ( req . user . id , ( err , user ) => {
186
182
if ( err ) { return next ( err ) ; }
187
183
user . password = req . body . password ;
@@ -197,8 +193,7 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => {
197
193
* POST /account/delete
198
194
* Delete user account.
199
195
*/
200
- export const postDeleteAccount : genericExpressMethod = ( req , res , next ) => {
201
- // const user = req.user as UserDocument;
196
+ export const postDeleteAccount = ( req : Request , res : Response , next : NextFunction ) => {
202
197
User . remove ( { _id : req . user . id } , ( err ) => {
203
198
if ( err ) { return next ( err ) ; }
204
199
req . logout ( ) ;
@@ -211,12 +206,10 @@ export const postDeleteAccount: genericExpressMethod = (req, res, next) => {
211
206
* GET /account/unlink/:provider
212
207
* Unlink OAuth provider.
213
208
*/
214
- export const getOauthUnlink : genericExpressMethod = ( req , res , next ) => {
209
+ export const getOauthUnlink = ( req : Request , res : Response , next : NextFunction ) => {
215
210
const provider = req . params . provider ;
216
- // const user = req.user as UserDocument;
217
211
User . findById ( req . user . id , ( err , user ) => {
218
212
if ( err ) { return next ( err ) ; }
219
- // user[provider] = undefined;
220
213
user . tokens = user . tokens . filter ( ( token : AuthToken ) => token . kind !== provider ) ;
221
214
user . save ( ( err : WriteError ) => {
222
215
if ( err ) { return next ( err ) ; }
@@ -230,7 +223,7 @@ export const getOauthUnlink: genericExpressMethod = (req, res, next) => {
230
223
* GET /reset/:token
231
224
* Reset Password page.
232
225
*/
233
- export const getReset : genericExpressMethod = ( req , res , next ) => {
226
+ export const getReset = ( req : Request , res : Response , next : NextFunction ) => {
234
227
if ( req . isAuthenticated ( ) ) {
235
228
return res . redirect ( "/" ) ;
236
229
}
@@ -253,7 +246,7 @@ export const getReset: genericExpressMethod = (req, res, next) => {
253
246
* POST /reset/:token
254
247
* Process the reset password request.
255
248
*/
256
- export const postReset : genericExpressMethod = ( req , res , next ) => {
249
+ export const postReset = ( req : Request , res : Response , next : NextFunction ) => {
257
250
check ( "password" , "Password must be at least 4 characters long." ) . isLength ( { min : 4 } ) ;
258
251
check ( "confirm" , "Passwords must match." ) . equals ( req . body . password ) ;
259
252
@@ -328,7 +321,7 @@ export const getForgot = (req: Request, res: Response) => {
328
321
* POST /forgot
329
322
* Create a random token, then the send user an email with a reset link.
330
323
*/
331
- export const postForgot : genericExpressMethod = ( req , res , next ) => {
324
+ export const postForgot = ( req : Request , res : Response , next : NextFunction ) => {
332
325
check ( "email" , "Please enter a valid email address." ) . isEmail ( ) ;
333
326
// eslint-disable-next-line @typescript-eslint/camelcase
334
327
sanitize ( "email" ) . normalizeEmail ( { gmail_remove_dots : false } ) ;
0 commit comments