Skip to content

Commit

Permalink
feat(password-reset): adds swagger api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldare committed Mar 14, 2019
1 parent c1ccc7e commit fbd91e0
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 172 deletions.
8 changes: 4 additions & 4 deletions server/config/db-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module.exports = {
development: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false
operatorsAliases: false,
},
test: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false
operatorsAliases: false,
},
production: {
env_variable: 'DATABASE_URL',
dialect: 'postgres',
operatorsAliases: false,
logging: false
}
logging: false,
},
};
2 changes: 1 addition & 1 deletion server/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
secret: process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret'
secret: process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret',
};
8 changes: 5 additions & 3 deletions server/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ export const validate = (value, schema) =>
*/
export const generateVerificationLink = token =>
UI_CLIENT_HOST
? `${UI_CLIENT_HOST}/users/verify/?token=${token}`
: `${API_SERVER_HOST}/api/users/verify/?token=${token}`;
? `${UI_CLIENT_HOST}/users/verify?token=${token}`
: `${API_SERVER_HOST}/api/users/verify?token=${token}`;

/**
* Generate a user account password reset link
* @param {string} token password reset token
* @returns {URL} Verification url
*/
export const generateResetLink = token =>
`${API_SERVER_HOST}/api/users/reset-password/?token=${token}`;
UI_CLIENT_HOST
? `${UI_CLIENT_HOST}/users/reset-password?token=${token}`
: `${API_SERVER_HOST}/api/users/reset-password?token=${token}`;
221 changes: 193 additions & 28 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
"url": "https://opensource.org/licenses/MIT"
}
},
"host": "https://vale-ah-backend-staging.herokuapp.com",
"basePath": "/api",
"servers": [
{
"url": "https://vale-ah-backend-staging.herokuapp.com"
}
],
"tags": [
{
"name": "Naija Recipes",
Expand Down Expand Up @@ -61,39 +65,167 @@
}
}
},
"/users/verify" : {
"get" : {
"description" : "Verify if the user is verified",
"parameters" : [ {
"name" : "token",
"in" : "query",
"schema" : {
"type" : "string"
},
"example" : "eyJhbGciOiJIUzI1NiJ9.Mg.hbsvkNj_kZvQYNtZxa4r2GXoNRLq1q4xC9qSq48Dwhw"
} ],
"responses" : {
"500" : {
"description" : "Database connection error"
"/users/verify": {
"get": {
"description": "Verify if the user is verified",
"parameters": [
{
"name": "token",
"in": "query",
"schema": {
"type": "string"
},
"example": "eyJhbGciOiJIUzI1NiJ9.Mg.hbsvkNj_kZvQYNtZxa4r2GXoNRLq1q4xC9qSq48Dwhw"
}
],
"responses": {
"500": {
"description": "Database connection error"
},
"400" : {
"description" : "Verification token error",
"content" : {
"application/json; charset=utf-8" : {
"schema" : {
"type" : "string"
"400": {
"description": "Verification token error",
"content": {
"application/json; charset=utf-8": {
"schema": {
"type": "string"
}
}
}
},
"200" : {
"description" : "Account verification success"
"200": {
"description": "Account verification success"
}
}
},
"servers" : [ {
"url" : "https://vale-ah-backend-staging.herokuapp.com"
} ]
"servers": [
{
"url": "https://vale-ah-backend-staging.herokuapp.com"
}
]
},
"/users/reset-password/email": {
"post": {
"tags": [
"Password reset "
],
"description": "Sends a password reset link to the user's email",
"requestBody": {
"content": {
"application/json": {
"examples": {
"0": {
"value": "{\n\t\"email\": \"segun.oluwadare@andela.com\"\n}"
}
}
}
}
},
"parameters": [
{
"in": "body",
"name": "email",
"description": "The password reset link is sent to the inputed email",
"required": true,
"schema": {
"$ref": "#/definitions/SendResetPasswordEmail"
}
}
],
"responses": {
"200": {
"description": "Password reset link sent successfully"
},
"404": {
"description": "User not found!"
},
"500": {
"description": "Cannot send password reset link"
}
}
}
},
"/users/reset-password/": {
"get": {
"tags": [
"Password reset "
],
"description": "Validats the JWT Token and sends it as a response",
"parameters": [
{
"name": "token",
"in": "query",
"required": false,
"description": "password reset token",
"style": "form",
"explode": true,
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN5bHZhIiwiaWQiOjEsImlhdCI6MTU1MjMyODAxOCwiZXhwIjoxNTUyOTMyODE4fQ.wfzLHdfmaSpaLomgCnwnn-TtW1qQas6S7ModYn_XT98"
}
],
"responses": {
"200": {
"description": "token"
},
"400": {
"description": "JWT error messages"
}
}
}
},
"/users/reset-password": {
"post": {
"tags": [
"Password reset "
],
"security": [
{
"tokenAuth": []
}
],
"description": "Auto generated using Swagger Inspector",
"parameters": [
{
"name": "password",
"in": "body",
"required": true,
"description": "password reset field",
"style": "form",
"explode": true,
"schema": {
"$ref": "#/definitions/ResetPasswordField"
}
},
{
"name": "Authorization",
"in": "headers",
"required": true,
"description": "token"
}
],
"requestBody": {
"content": {
"application/json": {
"examples": {
"0": {
"value": "{\n \"password\": \"hellomary\"\n}"
}
}
}
}
},
"responses": {
"200": {
"description": "Auto generated using Swagger Inspector",
"content": {
"application/json; charset=utf-8": {
"schema": {
"type": "string"
},
"examples": {}
}
}
}
}
}
}
},
"definitions": {
Expand All @@ -114,6 +246,39 @@
"type": "string"
}
}
},
"SendResetPasswordEmail": {
"required": [
"email"
],
"properties": {
"email": {
"type": "string"
}
}
},
"ResetPasswordField": {
"required": [
"password"
],
"properties": {
"password": {
"type": "string"
}
}
}
},
"components": {
"securitySchemes": {
"tokenAuth": {
"type": "http",
"scheme": "bearer"
}
}
},
"security": [
{
"tokenAuth": []
}
}
}
]
}
Loading

0 comments on commit fbd91e0

Please sign in to comment.