Skip to content

Commit

Permalink
find forgot account
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielzxccc committed May 1, 2024
1 parent 2b3876b commit 2449686
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/modules/Auth/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,16 @@ export async function updatePassword(req: SessionRequest, res: Response) {
errorHandler(res, error)
}
}

export async function findForgottenAccount(req: SessionRequest, res: Response) {
try {
const { body } = await zParse(Schema.ForgottenAccount, req)

const data = await Interactor.findForgottenAccount(body.account)
// await Interactor.updatePassword({ userid, newPassword, oldPassword })

res.status(200).json(data)
} catch (error) {
errorHandler(res, error)
}
}
16 changes: 16 additions & 0 deletions src/modules/Auth/AuthInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ export async function authenticateUser(credentials: string, password: string) {
return user
}

export async function findForgottenAccount(account: string) {
const user = await Service.findByEmailOrUsername(account)

if (!user) {
throw new HttpError('Invalid email or contact', 401)
}

if (user.isbanned) {
throw new HttpError('Your account has been banned.', 401)
}

const { avatar, firstname, lastname, email, username, contact_number } = user

return { avatar, firstname, lastname, email, username, contact_number }
}

export async function registerUser(credentials: RegisterUser) {
const { phone_number, email, password, confirmPassword } = credentials.body

Expand Down
73 changes: 73 additions & 0 deletions src/modules/Auth/AuthOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,76 @@
* type: string
* description: Confirm the new password
*/

/**
* @openapi
* /api/auth/find/forgotten/account:
* post:
* summary: Find forgotten account
* tags:
* - Auth
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ForgottenAccountJSON"
* responses:
* "200":
* description: Account found successfully
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ForgottenAccountResponse"
* "401":
* description: Unauthorized
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ErrorResponse"
* "400":
* description: Validation Error
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ErrorResponse"
* "404":
* description: Not Found Error
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ErrorResponse"
* "500":
* description: Server Error
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ServerError"
*/

/**
* @openapi
* components:
* schemas:
* ForgottenAccountJSON:
* type: object
* properties:
* account:
* type: string
*
* ForgottenAccountResponse:
* type: object
* properties:
* avatar:
* type: string
* firstname:
* type: string
* lastname:
* type: string
* email:
* type: string
* username:
* type: string
* contact_number:
* type: string
*/
2 changes: 2 additions & 0 deletions src/modules/Auth/AuthRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,5 @@ AuthRouter.post(
)

AuthRouter.post('/update/password', AuthController.updatePassword)

AuthRouter.post('/find/forgotten/account', AuthController.findForgottenAccount)
6 changes: 6 additions & 0 deletions src/schema/AuthSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,9 @@ export const UpdatePassword = z.object({
path: ['confirmPassword'], // path of error
}),
})

export const ForgottenAccount = z.object({
body: z.object({
account: z.string(),
}),
})

0 comments on commit 2449686

Please sign in to comment.