-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
9,346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = false | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# DB | ||
MONGO_URI= | ||
# TOKEN | ||
SALTROUNDS= | ||
EXPIRESIN= | ||
JWT_SECRET= | ||
JWT_EXPIRATION_IN_MINUTES= | ||
# EMAILS | ||
EMAIL_FROM_NAME= | ||
EMAIL_FROM_ADDRESS= | ||
EMAIL_SMTP_DOMAIN_MAILGUN= | ||
EMAIL_SMTP_API_MAILGUN= | ||
# FRONTEND | ||
FRONTEND_URL=http://localhost:8080 | ||
# ENVIRONMENT | ||
NODE_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es2020": true, | ||
"node": true | ||
}, | ||
"extends": "airbnb", | ||
"parserOptions": { | ||
"ecmaVersion": 11 | ||
}, | ||
"rules": { | ||
//custom | ||
"callback-return": [ | ||
"error", | ||
["done", "proceed", "next", "onwards", "callback", "cb"] | ||
], | ||
// "no-extra-semi": ["warn"], | ||
"max-nested-callbacks": ["off"], | ||
"no-unused-vars": [ | ||
"warn", | ||
{ | ||
"caughtErrors": "all", | ||
"caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)" | ||
} | ||
], | ||
//end | ||
"import/no-extraneous-dependencies": ["error", { | ||
"devDependencies": true | ||
}], | ||
"no-async-promise-executor": ["off"], | ||
"no-plusplus": [2, { | ||
"allowForLoopAfterthoughts": true | ||
}], | ||
"implicit-arrow-linebreak": ["off"], | ||
"no-param-reassign": ["off"], | ||
"operator-linebreak": ["off"], | ||
"no-underscore-dangle": ["off"], | ||
"no-prototype-builtins": ["off"], //like hasownproperty | ||
"no-use-before-define": ["off"], | ||
"consistent-return": ["off"], | ||
"new-cap": ["off"], //CHECK LATER New Model | ||
"prefer-const": ["off"], | ||
"camelcase": ["off"], | ||
"no-iterator": ["off"], | ||
"no-console": ["off"], | ||
"global-require": ["off"], | ||
"no-restricted-syntax": ["off"], | ||
"import/no-dynamic-require": ["off"], | ||
"no-await-in-loop": ["off"], | ||
"comma-dangle": [2, "always-multiline"], | ||
"quotes": [ | ||
"warn", | ||
"single", | ||
{ | ||
"avoidEscape": false, | ||
"allowTemplateLiterals": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
client/node_modules | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "all", | ||
"semi": true, | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"eslint.validate": ["javascript"], | ||
"eslint.workingDirectories": [{ | ||
"mode": "auto" | ||
}], | ||
"javascript.suggestionActions.enabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const mongoose = require('mongoose'); | ||
mongoose.plugin(require('mongoose-beautiful-unique-validation')); // unique validator | ||
mongoose.plugin(require('mongoose-paginate-v2')); // paginator | ||
mongoose.plugin(require('mongoose-aggregate-paginate-v2')); | ||
// aggregate paginator | ||
const DB_URL = process.env.MONGO_URI; | ||
const loadModels = require('../models'); | ||
|
||
module.exports = () => { | ||
const connect = () => { | ||
mongoose.Promise = global.Promise; | ||
|
||
mongoose.connect( | ||
DB_URL, | ||
{ | ||
keepAlive: true, | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}, | ||
(err) => { | ||
let dbStatus = ''; | ||
if (err) { | ||
dbStatus = `* Error connecting to DB: ${err}\n****************************\n`; | ||
} | ||
dbStatus = '* DB Connection: OK\n****************************\n'; | ||
if (process.env.NODE_ENV !== 'test') { | ||
// Prints initialization | ||
console.log('****************************'); | ||
console.log('* Starting Server'); | ||
console.log(`* Port: ${process.env.PORT || 3000}`); | ||
console.log(`* NODE_ENV: ${process.env.NODE_ENV}`); | ||
console.log('* Database: MongoDB'); | ||
console.log(dbStatus); | ||
} | ||
}, | ||
); | ||
mongoose.set('useCreateIndex', true); | ||
mongoose.set('useFindAndModify', false); | ||
}; | ||
connect(); | ||
|
||
mongoose.connection.on('error', console.log); | ||
mongoose.connection.on('disconnected', connect); | ||
|
||
loadModels(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const passport = require('passport'); | ||
const JwtStrategy = require('passport-jwt').Strategy; | ||
const User = require('../models/Users'); | ||
const auth = require('../helpers/auth'); | ||
|
||
/** | ||
* Extracts token from: header, body or query | ||
* @param {Object} req - request object | ||
* @returns {string} token - decrypted token | ||
*/ | ||
const jwtExtractor = (req) => { | ||
let token = null; | ||
if (req.headers.authorization) { | ||
token = req.headers.authorization.replace('Bearer ', '').trim(); | ||
} else if (req.body.token) { | ||
token = req.body.token.trim(); | ||
} else if (req.query.token) { | ||
token = req.query.token.trim(); | ||
} | ||
if (token) { | ||
// Decrypts token | ||
token = auth.decrypt(token); | ||
} | ||
return token; | ||
}; | ||
/** | ||
* Options object for jwt middlware | ||
*/ | ||
const jwtOptions = { | ||
jwtFromRequest: jwtExtractor, | ||
secretOrKey: process.env.JWT_SECRET, | ||
}; | ||
/** | ||
* Login with JWT middleware | ||
*/ | ||
const jwtLogin = new JwtStrategy(jwtOptions, (payload, done) => { | ||
User.findById(payload.data._id, (err, user) => { | ||
if (err) { | ||
return done(err, false); | ||
} | ||
return !user ? done(null, false) : done(null, user); | ||
}); | ||
}); | ||
|
||
passport.use(jwtLogin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const { check } = require('express-validator'); | ||
const { validationResult } = require('../helpers/utils'); | ||
|
||
/** | ||
* Validates register request | ||
*/ | ||
exports.register = [ | ||
check('first_name') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY'), | ||
check('last_name') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY'), | ||
check('email') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isEmail() | ||
.withMessage('EMAIL_IS_NOT_VALID'), | ||
check('password') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isLength({ | ||
min: 5, | ||
}) | ||
.withMessage('PASSWORD_TOO_SHORT_MIN_5'), | ||
(req, res, next) => { | ||
validationResult(req, res, next); | ||
}, | ||
]; | ||
|
||
/** | ||
* Validates login request | ||
*/ | ||
exports.login = [ | ||
check('email') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isEmail() | ||
.withMessage('EMAIL_IS_NOT_VALID'), | ||
check('password') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isLength({ | ||
min: 5, | ||
}) | ||
.withMessage('PASSWORD_TOO_SHORT_MIN_5'), | ||
(req, res, next) => { | ||
validationResult(req, res, next); | ||
}, | ||
]; | ||
|
||
/** | ||
* Validates verify request | ||
*/ | ||
exports.verify = [ | ||
check('id') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY'), | ||
(req, res, next) => { | ||
validationResult(req, res, next); | ||
}, | ||
]; | ||
|
||
/** | ||
* Validates forgot password request | ||
*/ | ||
exports.forgotPassword = [ | ||
check('email') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isEmail() | ||
.withMessage('EMAIL_IS_NOT_VALID'), | ||
(req, res, next) => { | ||
validationResult(req, res, next); | ||
}, | ||
]; | ||
|
||
/** | ||
* Validates reset password request | ||
*/ | ||
exports.resetPassword = [ | ||
check('id') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY'), | ||
check('password') | ||
.exists() | ||
.withMessage('MISSING') | ||
.not() | ||
.isEmpty() | ||
.withMessage('IS_EMPTY') | ||
.isLength({ | ||
min: 5, | ||
}) | ||
.withMessage('PASSWORD_TOO_SHORT_MIN_5'), | ||
(req, res, next) => { | ||
validationResult(req, res, next); | ||
}, | ||
]; |
Oops, something went wrong.