From d9b80c6af09a6c1447319af0de51ff1db9e1c5a0 Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Wed, 27 Nov 2024 17:55:58 +0700 Subject: [PATCH] reset password --- src/controllers/auth.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/routes/public.ts | 4 +++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index 550263b..2dca6b6 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -139,6 +139,44 @@ export class AuthController { } } + static async resetPassword(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Auth'] + #swagger.parameters['email'] = { + in: 'path', + description: 'Email', + required: true, + type: 'string' + } + */ + + try { + const schema = Joi.object().keys({ + email: Joi.string().email().required().label('Email'), + }); + + const param: User = await schema.validateAsync(req.params); + + const userRepository = OrmHelper.DB.getRepository(User); + const userRefreshTokenRepository = OrmHelper.DB.getRepository(UserRefreshToken); + + const user = await userRepository.findOne({ + select: ['id', 'email', 'password', 'username'], + where: { username: param.username }, + }) + + return ReturnHelper.successResponseAny(res, 200, Language.lang.success, {}); + + + // return ReturnHelper.errorResponse(res, 403, 401, Language.lang.failed_access); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + + return ReturnHelper.errorResponse(res, 500, 402, Language.lang.failed, err.message); + } + } + static async renewToken(req: Request, res: Response, next: NextFunction): Promise { /* #swagger.tags = ['Auth'] diff --git a/src/routes/public.ts b/src/routes/public.ts index 68a3b3c..0797b46 100644 --- a/src/routes/public.ts +++ b/src/routes/public.ts @@ -1,12 +1,14 @@ import express from 'express'; import { AuthController } from '../controllers/auth'; +import { UserController } from '../controllers/user'; export class RoutePublic { static setup(app: express.Application) { app.post('/api/login', AuthController.login) - app.post('/api/reset_password', AuthController.login) + app.put('/api/reset_password/:email', AuthController.resetPassword) + app.put('/api/update_password/:token', UserController.updatePassword) app.put('/api/logout/:refresh_token', AuthController.logout) app.put('/api/renew_token/:refresh_token', AuthController.renewToken)