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 all 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
46 changes: 44 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Mentoring User Service Config
APPLICATION_PORT = 3000
APPLICATION_ENV = development

APPLICATION_PORT = 3000 // Port on which service runs

APPLICATION_ENV = development // Service environment

MONGODB_URL = mongodb://localhost:27017/elevate-user // Database connectivity url

SALT_ROUNDS = 10 // Number of rounds for encryption

ACCESS_TOKEN_SECRET = 'bsj82AHBxahusub12yexlashsbxAXADHBlaj' // Token secret to generate access token

REFRESH_TOKEN_SECRET = 'baXDUDQ7YEXKH182ELXKJHJKLhasjxlADahgdsd' // Token secret to generate refresh token

# KAFKA Configurations

KAFKA_URL = localhost:9092 // Kafka hosted server url
KAFKA_GROUP_ID = userservice // Kafka group to which consumer belongs
KAFKA_TOPIC = // Kafka topic to consume data from
NOTIFICATION_KAFKA_TOPIC = notificationtopic // Kafka topic to push notification data

# CLOUD STOARGE TYPE

CLOUD_STORAGE = 'GCP/AWS/AZURE' // Any one of three features available for cloud storage

# GCP Credentials

GCP_PATH = 'gcp.json' // Gcp json config file path
DEFAULT_GCP_BUCKET_NAME = 'gcp-bucket-storage-name' // Gcp bucket name which stores files
GCP_PROJECT_ID = 'project-id' // Gcp project id

# AWS Credentials

AWS_ACCESS_KEY_ID = 'ashdaqwgeiqwye739182xo1y371xo1237o' // Aws access key id
AWS_SECRET_ACCESS_KEY = '189273bxoyeb1yxliuxb173t71x17x173o1' // Aws secret access key
AWS_BUCKET_REGION = 'ap-south-1' // Aws region where bucket will be located
AWS_BUCKET_ENDPOINT = 's3.ap-south-1.amazonaws.com' // Aws end point
DEFAULT_AWS_BUCKET_NAME = 'aws-bucket-storage-name' // Aws bucket name which stores files

# AZURE Credentials

AZURE_ACCOUNT_NAME = 'account-name' // Azure storage account name
AZURE_ACCOUNT_KEY = 'xbad1y381xuhebbi27234724x1yphqbe848hkqje1u3==' // Azure storage account key
DEFAULT_AZURE_CONTAINER_NAME = 'azure-container-storage-name' // Azure storage container which stores files
INTERNAL_ACCESS_TOKEN = 'baXDUDQ7YEXKH182ELXKJHJKLhasjxlADahgdsd'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ build/Release

# Dependency directories
node_modules
tmp
jspm_packages
doc
.vscode
Expand Down Expand Up @@ -58,9 +59,13 @@ package-lock.json

public/assessment/web
public/assessment/web2
public/tmp

.env

# Ignore all credentials
generics/helpers/credentials/*

gcp.json
gcp1.json

7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
require("dotenv").config({ path: './.env.sample' });
const expressFileUpload = require('express-fileupload');

require('dotenv').config({ path: './.env' });
require('./configs');

const app = express();

app.use(cors());

app.use(expressFileUpload());

app.use(bodyParser.urlencoded({ extended: true, limit: '50MB' }));
app.use(bodyParser.json({ limit: '50MB' }));

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

require("./mongodb")();

require("./kafka")();
const path = require("path");
const fs = require("fs");
const requireAll = require("require-all");

global.PROJECT_ROOT_DIRECTORY = path.join(__dirname, '..');

//load base v1 controllers
const pathToController = PROJECT_ROOT_DIRECTORY + "/controllers/v1/";

fs.readdirSync(pathToController).forEach(function (file) {
checkWhetherFolderExistsOrNot(pathToController, file);
});

/**
* Check whether folder exists or Not.
* @method
* @name checkWhetherFolderExistsOrNot
* @param {String} pathToFolder - path to folder.
* @param {String} file - File name.
*/

function checkWhetherFolderExistsOrNot(pathToFolder, file) {

let folderExists = fs.lstatSync(pathToFolder + file).isDirectory();

if (folderExists) {
fs.readdirSync(pathToFolder + file).forEach(function (folderOrFile) {
checkWhetherFolderExistsOrNot(pathToFolder + file + "/", folderOrFile);
})

} else {
if (file.match(/\.js$/) !== null) {
require(pathToFolder + file);
}
}

}


// All controllers
global.controllers = requireAll({
dirname: PROJECT_ROOT_DIRECTORY + "/controllers",
resolve: function (Controller) {
return new Controller();
}
});
Empty file removed configs/kafka-config.js
Empty file.
50 changes: 50 additions & 0 deletions configs/kafka.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* name : configs/kafka
* author : Aman Gupta
* Date : 08-Nov-2021
* Description : Kafka connection configurations
*/

const Kafka = require('kafka-node');

module.exports = () => {
const Producer = Kafka.Producer;
const KafkaClient = new Kafka.KafkaClient({
kafkaHost: process.env.KAFKA_URL
});
const producer = new Producer(KafkaClient);

/* Uncomment while writing consuming actions for this service */
// const Consumer = Kafka.Consumer;
// const consumer = new Consumer(KafkaClient, [ { topic: process.env.KAFKA_TOPIC } ], { autoCommit: true, groupId: process.env.KAFKA_GROUP_ID })

/* Registered events */

KafkaClient.on('error', error => {
console.log('Kafka connection error: ', error);
});

KafkaClient.on('connect', () => {
console.log('Connected to kafka client');
});

producer.on('error', error => {
console.log('Kafka producer intialization error: ', error);
});

producer.on('ready', () => {
console.log('Producer intialized successfully');
});

// consumer.on('error', error => {
// console.log('Kafka consumer intialization error: ', error);
// });

// consumer.on('message', message => {
// // perform action using message
// });

global.kafkaProducer = producer;
global.kafkaClient = KafkaClient;

};
43 changes: 43 additions & 0 deletions configs/mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* name : configs/mongodb
* author : Aman
* Date : 07-Oct-2021
* Description : Mongodb connections configurations
*/

const mongoose = require("mongoose");
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_paginate);
global.db = db;
};
41 changes: 40 additions & 1 deletion constants/api-responses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
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",
"INVALID_REFRESH_TOKEN": "Invalid refresh token",
"REFRESH_TOKEN_NOT_FOUND": "Refresh token not found",
"PROFILE_UPDATED_SUCCESSFULLY": "Profile updated successfully",
"PROFILE_FETCHED_SUCCESSFULLY": "Profile fetched successfully",
"FORM_ALREADY_EXISTS": "Form already exists",
"FORM_CREATED_SUCCESSFULLY": "Form created successfully",
"FORM_UPDATED_SUCCESSFULLY": "Form updated successfully",
"FORM_FETCHED_SUCCESSFULLY": "Form fetched successfully",
"FORM_NOT_FOUND": "Form not found",
"USER_ENTITY_NOT_FOUND": "User entity not found",
"USER_ENTITY_ALREADY_EXISTS": "User entity already exists",
"USER_ENTITY_ALREADY_DELETED": "User entity already deleted",
"USER_ENTITY_CREATED_SUCCESSFULLY": "User entity created successfully",
"USER_ENTITY_UPDATED_SUCCESSFULLY": "User entity updated successfully",
"USER_ENTITY_DELETED_SUCCESSFULLY": "User entity deleted successfully",
"USER_ENTITY_FETCHED_SUCCESSFULLY": "User entity fetched successfully",
"OTP_SENT_SUCCESSFULLY": "Otp sent successfully",
"PASSWORD_RESET_SUCCESSFULLY": "Password reset successfully",
"OTP_INVALID": "Invalid otp",
"SYSTEM_USER_ALREADY_EXISTS": "System User already exists",
"NOT_AN_ADMIN": "Not an admin",
"MENTOR_LIST": "Mentor list fetched successfully",
"FILE_NOT_PROVIDED": "File not provided",
"FILE_UPLOADED_SUCCESSFULLY": "File uploaded successfully",
"SIGNED_URL_GENERATED_SUCCESSFULLY": "Signed Url Generated Successfully",
"INCORRECT_INTERNAL_ACCESS_TOKEN": "Invalid internal access token",
"USER_IS_A_MENTOR":"User has mentor access",
"USER_IS_NOT_A_MENTOR":"User does't have mentor access",
"USER_UPDATED_SUCCESSFULLY": "User successfully updated"
};
25 changes: 19 additions & 6 deletions constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* Description : All commonly used constants through out the service
*/

const successResponse = (statusCode = 500, message, data = [], totalCounts = undefined, token = undefined) => {
const successResponse = ({statusCode = 500, responseCode = 'OK', message, result = []}) => {
return {
statusCode,
responseCode,
message,
data,
totalCounts,
token
result
}
};

const failureResponse = ({ message = "Oops! Something Went Wrong.", statusCode = 500 }) => {
const failureResponse = ({ message = "Oops! Something Went Wrong.", statusCode = 500, responseCode }) => {
const error = new Error(message);
error.statusCode = statusCode;
error.responseCode = responseCode;
return error;
};

Expand All @@ -27,5 +27,18 @@ module.exports = {
DEFAULT_PAGE_SIZE: 100,
},
successResponse,
failureResponse
failureResponse,
guestUrls: [
'/user/v1/account/login',
'/user/v1/account/create',
'/user/v1/account/generateToken',
'/user/v1/account/generateOtp',
'/user/v1/account/resetPassword',
'/user/v1/systemUsers/create',
'/user/v1/systemUsers/login'
],
uploadUrls: [
'bulkCreateMentors',
'/user/v1/account/verifyMentor'
]
};
3 changes: 0 additions & 3 deletions constants/end-points.js

This file was deleted.

Loading