Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDED: Login, Register, regenerate access token, logout services #1

Merged
merged 44 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
157aebd
Modified project structure
aman-tunerlabs Oct 8, 2021
c306433
Modified folder
aman-tunerlabs Oct 12, 2021
fbf4450
Update user project
aman-tunerlabs Oct 12, 2021
fa14774
ADDED: Login, Register, regenerate access token, logout services
aman-g202 Oct 21, 2021
c38aecd
Improvements in account apis
aman-g202 Oct 27, 2021
88a3644
otpInfo removed from login response
aman-g202 Oct 27, 2021
816ab2a
url validation in authentiator fixed
aman-g202 Oct 27, 2021
7cbf72c
Route url fixed, prepended /user
aman-g202 Oct 27, 2021
c2650c2
ADDED: refresh token storage and validation from db, IMPROVED: code
aman-g202 Oct 28, 2021
aec67eb
IMPROVED: Removed email input from regenerate access token
aman-g202 Oct 29, 2021
4067417
ADDED: Profile update and profile fetch details apis
aman-g202 Nov 2, 2021
0cd6af5
ADDED: Form Create, Update, Read Api for user service
aman-g202 Nov 3, 2021
2e424ec
FIXED: user profile update api changes
aman-g202 Nov 4, 2021
e872007
ADDED: CRUD apis for user entities such as roles/expertise/locations etc
aman-g202 Nov 4, 2021
03a8c7e
Small Fixes
aman-g202 Nov 4, 2021
b80491a
ADDED: Forget password flow
aman-g202 Nov 8, 2021
2abadf2
ADDED: Forget password flow
aman-g202 Nov 8, 2021
7516666
UPDATED: Form apis crud
aman-g202 Nov 9, 2021
b89a0ba
ADDED: Image upload in GCP and AWS
aman-g202 Nov 11, 2021
6de97e4
ADDED: Azure support to upload file
aman-g202 Nov 11, 2021
e1b2d60
UPDATED: Reset password api
aman-g202 Nov 11, 2021
f202b4c
UPDATED: Reset password api
aman-g202 Nov 11, 2021
39d1c5b
Mentors directory created
aman-tunerlabs Nov 12, 2021
bc47c1d
Resolved conflict
aman-tunerlabs Nov 12, 2021
d49455e
Added 404 logic
aman-tunerlabs Nov 12, 2021
f37aa55
Updated projection
aman-tunerlabs Nov 12, 2021
a49b5ea
Added internal access token
aman-tunerlabs Nov 12, 2021
2f0d953
Sorted based on name
aman-tunerlabs Nov 12, 2021
a8f9cdd
UPDATED: Login, entities apis
aman-g202 Nov 15, 2021
e19d152
UPDATED: Login, entities apis
aman-g202 Nov 15, 2021
ad7d40e
UPDATED: Login, entities apis
aman-g202 Nov 15, 2021
2b2555d
updated internal access check
aman-tunerlabs Nov 16, 2021
56882f2
Merge branch 'user-authentication' of https://github.com/ELEVATE-Proj…
aman-tunerlabs Nov 16, 2021
b6414cf
ADDED: Signed url upload feature for aws, gcp, azure
aman-g202 Nov 17, 2021
05e0718
ADDED: Signed url upload feature for aws, gcp, azure
aman-g202 Nov 17, 2021
ef72f7b
verifymentor api added
rakeshSgr Nov 18, 2021
2e5395e
Merge pull request #2 from ELEVATE-Project/verifyMentor
rakeshSgr Nov 18, 2021
8f323cc
fixing routing issue
rakeshSgr Nov 18, 2021
b05d422
Merge pull request #3 from ELEVATE-Project/verifyMentor
rakeshSgr Nov 18, 2021
3d209c9
user name added in to the token
rakeshSgr Nov 19, 2021
04eb68c
Merge pull request #4 from ELEVATE-Project/verifyMentor
rakeshSgr Nov 19, 2021
9987805
Modified express validator
aman-tunerlabs Dec 1, 2021
b461986
Api added for has accepted T and F
aman-tunerlabs Dec 1, 2021
eb080c9
Updated API
aman-tunerlabs Dec 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Mentoring User Service Config
APPLICATION_PORT = 3000
APPLICATION_ENV = development
APPLICATION_ENV = development
MONGODB_URL = mongodb://localhost:27017/elevate-user
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
SALT_ROUNDS = 10
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
require("dotenv").config({ path: './.env.sample' });
require('dotenv').config({ path: './.env.sample' });
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
require('./configs');

const app = express();

Expand Down
Empty file removed configs/db-config.js
Empty file.
Empty file removed configs/elastic-search-config.js
Empty file.
4 changes: 3 additions & 1 deletion configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* author : Aman Kumar Gupta
* Date : 31-Sep-2021
* Description : Contains connections of all configs
*/
*/

require("./mongodb")();
Empty file removed configs/kafka-config.js
Empty file.
45 changes: 45 additions & 0 deletions configs/mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* name : configs/mongodb
* author : Aman
* Date : 07-Oct-2021
* Description : Mongodb connections configurations
*/

const mongoose = require("mongoose");
const mongoose_delete = require("mongoose-delete");
const mongoose_autopopulate = require("mongoose-autopopulate");
const mongoose_timestamp = require("mongoose-timestamp");
const mongoose_paginate = require('mongoose-paginate-v2');

module.exports = function () {

// Added to remove depreciation warnings from logs.
mongoose.set('useCreateIndex', true)
mongoose.set('useFindAndModify', false)
mongoose.set('useUnifiedTopology', true)

const db = mongoose.createConnection(
process.env.MONGODB_URL,
{
useNewUrlParser: true
}
);

db.on("error", function () {
console.log("Database connection error:")
});

db.once("open", function () {
console.log("Connected to DB");
});

mongoose.plugin(mongoose_timestamp, {
createdAt: "createdAt",
updatedAt: "updatedAt"
});

mongoose.plugin(mongoose_autopopulate);
mongoose.plugin(mongoose_delete, { overrideMethods: true, deletedAt: true });
mongoose.plugin(mongoose_paginate);
global.db = db;
};
12 changes: 11 additions & 1 deletion constants/api-responses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
module.exports = {
'registeredSuccessfully': 'User Registered Successfully'
"EMAIL_INVALID": "Email Id is invalid",
"PASSWORD_INVALID": "Password is invalid",
"USER_ALREADY_EXISTS": "User already exists",
"USER_DOESNOT_EXISTS": "User doesnot exists",
"USER_CREATED_SUCCESSFULLY": "User created successfully",
"LOGGED_IN_SUCCESSFULLY": "User logged in successfully",
"LOGGED_OUT_SUCCESSFULLY": "User logged out successfully",
"UNAUTHORIZED_REQUEST": "Unauthorized request",
"REFRESH_TOKEN_EXPIRED": "Refresh token expired",
"ACCESS_TOKEN_EXPIRED": "Access token expired",
"ACCESS_TOKEN_GENERATED_SUCCESSFULLY": "Access token generated successfully",
};
7 changes: 5 additions & 2 deletions constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* Description : All commonly used constants through out the service
*/

const successResponse = (statusCode = 500, message, data = [], totalCounts = undefined, token = undefined) => {
const successResponse = ({statusCode = 500, message, data = [], totalCounts = undefined, accessToken = undefined, refreshToken = undefined}) => {
return {
statusCode,
message,
data,
totalCounts,
token
accessToken,
refreshToken
}
};

Expand All @@ -26,6 +27,8 @@ module.exports = {
DEFAULT_PAGE_NO: 1,
DEFAULT_PAGE_SIZE: 100,
},
accessTokenSecret: 'hsghasghjab1273JHajnbabsjdj1273981273jhajksdh8y3123yhjkah812398yhjqwe7617237yuhdhhdqwu271',
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
refreshTokenSecret: '371hkjkjady2y3ihdkajshdkiq23iuekw71yekhaskdvkvegavy23t78veqwexqvxveit6ttxyeeytt62tx236vv',
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
successResponse,
failureResponse
};
3 changes: 0 additions & 3 deletions constants/end-points.js

This file was deleted.

146 changes: 146 additions & 0 deletions controllers/v1/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* name : account.js
* author : Aman
* created-date : 07-Oct-2021
* Description : User Account.
*/

// Dependencies
const accountHelper = require("../../services/helper/account");

module.exports = class Account {

/**
* @api {post} /user/api/v1/account/create
* @apiVersion 1.0.0
* @apiName Creates User Account
* @apiGroup Accounts
* @apiParamExample {json} Request-Body:
* {
* "name" : "mentee name",
* "email" : "mentee@gmail.com",
* "password" : "menteepass",
* }
* @apiSampleRequest /user/api/v1/account/create
* @apiParamExample {json} Response:
* {
* "statusCode": 201,
* "message": "User created successfully",
* "data": []
* }
* @apiUse successBody
* @apiUse errorBody
*/

/**
* create mentee account
* @method
* @name create
* @param {Object} req -request data.
* @returns {JSON} - accounts creation.
*/

async create(req) {
const params = req.body;
try {
const createdAccount = await accountHelper.create(params);
return createdAccount;
} catch (error) {
return error;
}
}

/**
* @api {post} /user/api/v1/account/login
* @apiVersion 1.0.0
* @apiName Login User Account
* @apiGroup Accounts
* @apiParamExample {json} Request-Body:
* {
* "email" : "mentee@gmail.com",
* "password" : "menteepass",
* }
* @apiSampleRequest /user/api/v1/account/login
* @apiParamExample {json} Response:
* {
* "statusCode": 200,
* "message": "User logged in successfully",
* "data": {
* "email": {
* "verified": false,
* "address": "aman@gmail.com"
* },
* "designation": [],
* "isAMentor": false,
* "deleted": false,
* "_id": "61711e6c50cdf213e7971c2b",
* "name": "Aman",
* "password": "$2a$10$Z23WbUoimCVM32fwXtinXuvyxq4n4xvR0AwNJ4IjJtYJtuBn02ylu",
* "areasOfExpertise": [],
* "updatedAt": "2021-10-21T08:01:48.203Z",
* "createdAt": "2021-10-21T08:01:48.203Z",
* "__v": 0
* },
* "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Il9pZCI6IjYxNzExZTZjNTBjZGYyMTNlNzk3MWMyYiIsImVtYWlsIjoiYW1hbkBnbWFpbC5jb20iLCJpc0FNZW50b3IiOmZhbHNlfSwiaWF0IjoxNjM0ODE1MjU5LCJleHAiOjE2MzQ5MDE2NTl9.jkiotUxYbOZkZ3PLkOj-PdPoEbWfEI0gMfPqyfgzB5w",
* "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Il9pZCI6IjYxNzExZTZjNTBjZGYyMTNlNzk3MWMyYiIsImVtYWlsIjoiYW1hbkBnbWFpbC5jb20iLCJpc0FNZW50b3IiOmZhbHNlfSwiaWF0IjoxNjM0ODE1MjU5LCJleHAiOjE2NTA2MjY0NTl9.CjNSk6xPuHlPOcdTW9FflIlL9q-1MegE-GwpkBkbwZA"
* }
* @apiUse successBody
* @apiUse errorBody
*/

/**
* login user account
* @method
* @name login
* @param {Object} req -request data.
* @returns {JSON} - login details.
*/

async login(req) {
const params = req.body;
try {
const loggedInAccount = await accountHelper.login(params);
return loggedInAccount;
} catch (error) {
return error;
}
}

/**
* @api {post} /user/api/v1/account/logout
* @apiVersion 1.0.0
* @apiName Logouts User Account
* @apiGroup Accounts
* @apiParamExample {json} Request-Body:
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
* {
* "email" : "mentee@gmail.com"
* }
* @apiSampleRequest /user/api/v1/account/logout
* @apiParamExample {json} Response:
* {
* "statusCode": 200,
* "message": "User logged out successfully",
* "data": []
* }
* @apiUse successBody
* @apiUse errorBody
*/

/**
* logout user account
* @method
* @name create
* @param {Object} req -request data.
* @returns {JSON} - accounts loggedout.
*/

async logout(req) {
const params = req.body;
try {
const loggedOutAccount = await accountHelper.logout(params);
return loggedOutAccount;
} catch (error) {
return error;
}
}
}
23 changes: 23 additions & 0 deletions controllers/v1/mentors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* name : mentors.js
* author : Aman
* created-date : 12-Oct-2021
* Description : Mentors.
*/

// Dependencies
const mentorsHelper = require("../../services/helper/mentors");

module.exports = class Profile {
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved

list(req) {
return new Promise(async (resolve,reject) => {
try {
const listOfMentors = await mentorsHelper.list(req.body);
return resolve(listOfMentors);
} catch(error) {
return reject(error);
}
})
}
}
34 changes: 34 additions & 0 deletions controllers/v1/password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* name : password.js
* author : Aman
* created-date : 12-Oct-2021
* Description : User password.
*/

// Dependencies
const passwordHelper = require("../../services/helper/password");

module.exports = class Password {

forget(req) {
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
return new Promise(async (resolve,reject) => {
try {
const forgetPasswordData = await passwordHelper.forget(req.body);
return resolve(forgetPasswordData);
} catch(error) {
return reject(error);
}
})
}

reset(req) {
return new Promise(async (resolve,reject) => {
try {
const resetPasswordData = await passwordHelper.reset(req.params._id);
return resolve(resetPasswordData);
} catch(error) {
return reject(error);
}
})
}
}
45 changes: 45 additions & 0 deletions controllers/v1/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* name : password.js
* author : Aman
* created-date : 12-Oct-2021
* Description : User password.
*/

// Dependencies
const profileHelper = require("../../services/helper/profile");

module.exports = class Profile {

update(req) {
return new Promise(async (resolve,reject) => {
try {
const profileData = await profileHelper.update(req.body);
return resolve(profileData);
} catch(error) {
return reject(error);
}
})
}

form() {
aman-g202 marked this conversation as resolved.
Show resolved Hide resolved
return new Promise(async (resolve,reject) => {
try {
const profileForm = await profileHelper.form();
return resolve(profileForm);
} catch(error) {
return reject(error);
}
})
}

details(req) {
return new Promise(async (resolve,reject) => {
try {
const profileDetails = await profileHelper.details(req.params._id);
return resolve(profileDetails);
} catch(error) {
return reject(error);
}
})
}
}
Loading