diff options
author | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-22 12:35:43 -0400 |
---|---|---|
committer | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-22 12:35:43 -0400 |
commit | d31a740378e8d4fd58ec329ba83dd20d28bfe5b4 (patch) | |
tree | b46103d4f9fd2b04ccfc25023e1cb0156168f412 /src/server/authentication/AuthenticationManager.ts | |
parent | 62f9b89dad334d3d6405f5286e66b253090a82c7 (diff) | |
parent | 3f489c64d9e55d452c255f8e2c10b0d754883dbb (diff) |
Merge branch 'master' into lanyi-expanded-agent-paper-main
Diffstat (limited to 'src/server/authentication/AuthenticationManager.ts')
-rw-r--r-- | src/server/authentication/AuthenticationManager.ts | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/server/authentication/AuthenticationManager.ts b/src/server/authentication/AuthenticationManager.ts index 0cc1553c0..3c7858a72 100644 --- a/src/server/authentication/AuthenticationManager.ts +++ b/src/server/authentication/AuthenticationManager.ts @@ -26,21 +26,12 @@ export const getSignup = (req: Request, res: Response) => { return undefined; }; -const tryRedirectToTarget = (req: Request, res: Response) => { - const target = (req.session as any)?.target; - if (req.session && target) { - res.redirect(target); - } else { - res.redirect('/home'); - } -}; - /** * POST /signup * Create a new local account. */ export const postSignup = (req: Request, res: Response, next: NextFunction) => { - const email = req.body.email as String; + const email = req.body.email as string; check('email', 'Email is not valid').isEmail().run(req); check('password', 'Password must be at least 4 characters long').isLength({ min: 4 }).run(req); check('confirmPassword', 'Passwords do not match').equals(req.body.password).run(req); @@ -66,7 +57,7 @@ export const postSignup = (req: Request, res: Response, next: NextFunction) => { const user = new User(model); User.findOne({ email }) - .then((existingUser: any) => { + .then((existingUser: DashUserModel | null) => { if (existingUser) { return res.redirect('/login'); } @@ -74,13 +65,15 @@ export const postSignup = (req: Request, res: Response, next: NextFunction) => { .then(() => { req.logIn(user, err => { if (err) return next(err); - tryRedirectToTarget(req, res); + res.redirect('/home'); return undefined; }); }) + // eslint-disable-next-line @typescript-eslint/no-explicit-any .catch((err: any) => next(err)); return undefined; }) + // eslint-disable-next-line @typescript-eslint/no-explicit-any .catch((err: any) => next(err)); return undefined; }; @@ -108,7 +101,8 @@ export const getLogin = (req: Request, res: Response) => { export const postLogin = (req: Request, res: Response, next: NextFunction) => { if (req.body.email === '') { User.findOne({ email: 'guest' }) - .then((user: any) => !user && initializeGuest()) + .then((user: DashUserModel | null) => !user && initializeGuest()) + // eslint-disable-next-line @typescript-eslint/no-explicit-any .catch((err: any) => err); req.body.email = 'guest'; req.body.password = 'guest'; @@ -132,7 +126,7 @@ export const postLogin = (req: Request, res: Response, next: NextFunction) => { req.logIn(user, loginErr => { if (loginErr) { next(loginErr); - } else tryRedirectToTarget(req, res); + } else res.redirect('/home'); }); return undefined; }; @@ -163,15 +157,15 @@ export const postForgot = function (req: Request, res: Response, next: NextFunct const { email } = req.body; async.waterfall( [ - function (done: any) { - c.randomBytes(20, (err: any, buffer: Buffer) => { + function (done: (arg: null, token?: string) => void) { + c.randomBytes(20, (err: Error | null, buffer: Buffer) => { if (err) { done(null); } else done(null, buffer.toString('hex')); }); }, - function (token: string, done: any) { - User.findOne({ email }).then((user: any) => { + function (token: string, done: (arg: null, token: string, user: DashUserModel) => void) { + User.findOne({ email }).then((user: DashUserModel | null) => { if (!user) { // NO ACCOUNT WITH SUBMITTED EMAIL res.redirect('/forgotPassword'); @@ -182,7 +176,7 @@ export const postForgot = function (req: Request, res: Response, next: NextFunct user.save().then(() => done(null, token, user)); }); }, - function (token: Uint16Array, user: DashUserModel, done: any) { + function (token: Uint16Array, user: DashUserModel, done: (arg: null, token: Error | null, data: string) => void) { const smtpTransport = nodemailer.createTransport({ service: 'Gmail', auth: { @@ -220,7 +214,7 @@ export const postForgot = function (req: Request, res: Response, next: NextFunct export const getReset = function (req: Request, res: Response) { User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }) - .then((user: any) => { + .then((user: DashUserModel | null) => { if (!user) return res.redirect('/forgotPassword'); res.render('reset.pug', { title: 'Reset Password', @@ -234,9 +228,9 @@ export const getReset = function (req: Request, res: Response) { export const postReset = function (req: Request, res: Response) { async.waterfall( [ - function (done: any) { + function (done: (args: null, user: DashUserModel) => void) { User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }) - .then((user: any) => { + .then((user: DashUserModel | null) => { if (!user) return res.redirect('back'); check('password', 'Password must be at least 4 characters long').isLength({ min: 4 }).run(req); @@ -250,8 +244,8 @@ export const postReset = function (req: Request, res: Response) { user.save() .then( - () => (req as any).logIn(user), - (err: any) => err + // eslint-disable-next-line @typescript-eslint/no-explicit-any + () => req.logIn(user, (err: any) => err) ) .catch(() => res.redirect('/login')); done(null, user); @@ -259,7 +253,7 @@ export const postReset = function (req: Request, res: Response) { }) .catch(() => res.redirect('back')); }, - function (user: DashUserModel, done: any) { + function (user: DashUserModel, done: (args: null, error: Error | null) => void) { const smtpTransport = nodemailer.createTransport({ service: 'Gmail', auth: { |