Skip to content

Commit

Permalink
Merge pull request #190 from AltCamp/resetPassword
Browse files Browse the repository at this point in the history
docs: update documentation for forgot and reset password
  • Loading branch information
tobisupreme committed Jul 3, 2023
2 parents fbb455a + ce398d5 commit 4485d91
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/accounts/accountsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const resetPassword = async ({ token, newPassword }) => {

if (!userToken.token === token) throw new BadRequestError('Invalid token');

const isExpired = userToken.expiryTime.getTime() <= Date.now();
const isExpired = userToken.expiresAt.getTime() <= Date.now();
if (isExpired) {
TokenService.deleteToken(userToken._id);
throw new BadRequestError('Expired token');
Expand Down
154 changes: 152 additions & 2 deletions src/docs/endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ paths:
- Accounts
security:
- bearer: []
summary: Post a new question
description: This posts a new question
summary: Change password
description: This changes old password to a new one
requestBody:
content:
application/json:
Expand Down Expand Up @@ -397,6 +397,69 @@ paths:
schema:
$ref: '#/components/schemas/ValidationError'

/accounts/forgot-password:
post:
tags:
- Accounts
summary: Request OTP to change password
description: This sends OTP to your mail for change of password
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/forgotPassword'

responses:
'200':
description: Returns request successful
content:
application/json:
schema:
$ref: '#/components/schemas/forgotPasswordResponse'

'400':
description: 'User does not exist'
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'

'500':
description: Email containing OTP was not sent
content:
application/json:
schema:
$ref: '#/components/schemas/MailServerError'

/accounts/reset-password:
post:
tags:
- Accounts
summary: Reset password using OTP
description: This resets your password using OTP
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/resetPassword'

responses:
'200':
description: Returns the user
content:
application/json:
schema:
$ref: '#/components/schemas/resetPasswordResponse'

'400':
description: An invalid token or the token has expired
content:
application/json:
schema:
$ref: '#/components/schemas/BadRequestError'

delete:
tags:
- Accounts
Expand Down Expand Up @@ -2340,6 +2403,32 @@ components:
password: newTestPassword1$
retypePassword: newTestPassword1$

forgotPassword:
title: Request OTP for password reset
required:
- email
type: object
properties:
email:
type: string
example:
email: test@example.com

resetPassword:
title: Reset password using OTP
required:
- token
- password
type: object
properties:
token:
type: string
password:
type: string
example:
token: 'A four digit token'
password: Otgj7346_h!&

ValidationError:
type: object
properties:
Expand All @@ -2355,6 +2444,21 @@ components:
message: One or more of user input not validated
error: Unprocessable Entity

MailServerError:
type: object
properties:
messsage:
type: string
statusCode:
type: number
default: 500
error:
type: string
example:
statusCode: 500
message: connect ECONNREFUSED host:port
error: Something went wrong

BadRequestError:
type: object
properties:
Expand Down Expand Up @@ -2968,6 +3072,52 @@ components:
type: string
__v:
type: number

forgotPasswordResponse:
type: object
properties:
statusCode:
type: number
default: 200
message:
type: string

resetPasswordResponse:
type: object
properties:
statusCode:
type: number
default: 200
message:
type: string
data:
type: object
properties:
isDeleted:
type: boolean
_id:
type: string
firstname:
type: string
lastname:
type: string
email:
type: string
accountType:
type: string
owner:
type: string
createdAt:
type: string
updatedAt:
type: string
bio:
type: string
profilePicture:
type: string
__v:
type: number

# ----------------------------------------------------
consolidated:
example:
Expand Down

0 comments on commit 4485d91

Please sign in to comment.