-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from andela/develop
Merge develop to master
- Loading branch information
Showing
95 changed files
with
17,073 additions
and
1,016 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,4 @@ | ||
{ | ||
"plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"], | ||
"presets": [ "es2015" ] | ||
} |
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 @@ | ||
DB_HOST= | ||
DB_USERNAME= | ||
DB_PASSWORD= | ||
DB_DATABASE= | ||
PORT= | ||
JWT_SECRET= | ||
EMAIL_ADDRESS= | ||
EMAIL_PASSWORD= | ||
HOST_URL= |
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 @@ | ||
/dist/** | ||
/mochawesome-report/** | ||
/node_modules/** | ||
/.env/** | ||
/coverage/** | ||
.eslintrc.json | ||
package.json | ||
package-lock.json | ||
doc.json |
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,37 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"root": true, | ||
"extends": "airbnb-base", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"one-var": 0, | ||
"one-var-declaration-per-line": 0, | ||
"new-cap": 0, | ||
"consistent-return": 0, | ||
"no-param-reassign": 0, | ||
"comma-dangle": 0, | ||
"curly": ["error", "multi-line"], | ||
"import/no-unresolved": [2, { "commonjs": true }], | ||
"no-shadow": ["error", { "allow": ["req", "res", "err"] }], | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": true, | ||
"requireReturnType": true, | ||
"requireParamDescription": false, | ||
"requireReturnDescription": true | ||
}], | ||
"require-jsdoc": ["error", { | ||
"require": { | ||
"FunctionDeclaration": true, | ||
"MethodDefinition": true, | ||
"ClassDeclaration": 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
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 @@ | ||
eslint: | ||
enabled: true | ||
config_file: .eslintrc.json |
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 @@ | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
"config": path.resolve('./config', 'config.js'), | ||
"models-path": path.resolve('./models'), | ||
"seeders-path": path.resolve('./seeders'), | ||
"migrations-path": path.resolve('./migrations') | ||
}; |
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,12 @@ | ||
language: node_js | ||
node_js: | ||
- "10" | ||
services: | ||
- postgresql | ||
before_script: | ||
- psql -c 'create database vidarapp;' -U postgres | ||
script: | ||
- npm install && npm install sequelize-cli -g | ||
- npm run test | ||
after_success: | ||
- npm run coverage |
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
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,103 @@ | ||
import passport from 'passport'; | ||
import { OAuth2Strategy as GoogleStrategy } from 'passport-google-oauth'; | ||
import { Strategy as FacebookStrategy } from 'passport-facebook'; | ||
import { User } from '../models'; | ||
|
||
passport.use(new GoogleStrategy( | ||
{ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: `${process.env.HOST_URL}/api/v1/auth/google/callback`, | ||
}, | ||
/** | ||
* callback function for google strategy | ||
* @param {object} accessToken authorization token | ||
* @param {object} refreshToken authorization token | ||
* @param {object} profile a user profile | ||
* @param {function} done end of function | ||
* @returns {function} callback | ||
*/ | ||
async (accessToken, refreshToken, profile, done) => { | ||
const email = profile.emails[0].value; | ||
/** | ||
* @description - finds an existing user or create a new user | ||
* @param {object} user a user | ||
* @param {function} done end of function | ||
* @returns {object} createOrFindUser | ||
*/ | ||
const { | ||
displayName, | ||
name: { givenName } | ||
} = profile; | ||
const user = await User.findOrCreate({ | ||
where: { email }, | ||
defaults: { | ||
name: displayName, | ||
username: givenName, | ||
} | ||
}); | ||
return done(null, user[0].dataValues); | ||
} | ||
)); | ||
|
||
/** | ||
* callback function for facebook strategy | ||
* @param {object} accessToken authorization token | ||
* @param {object} refreshToken authorization token | ||
* @param {object} profile a user profile | ||
* @param {function} done end of function | ||
* @returns {function} callback | ||
*/ | ||
passport.use(new FacebookStrategy( | ||
{ | ||
clientID: process.env.FACEBOOK_CLIENT_ID, | ||
clientSecret: process.env.FACEBOOK_CLIENT_SECRET, | ||
callbackURL: `${process.env.HOST_URL}/api/v1/auth/facebook/callback`, | ||
profileFields: ['id', 'displayName', 'email'] | ||
}, | ||
async (accessToken, refreshToken, profile, done) => { | ||
const email = profile.emails[0].value; | ||
const splitName = profile.displayName.split(' '); | ||
const username = splitName[0]; | ||
/** | ||
* @description - finds an existing user or create a new user | ||
* @param {object} user a user | ||
* @param {function} done end of function | ||
* @returns {object} createOrFindUser | ||
*/ | ||
const { displayName } = profile; | ||
const user = await User.findOrCreate({ | ||
where: { email }, | ||
defaults: { | ||
name: displayName, | ||
username, | ||
} | ||
}); | ||
return done(null, user[0]); | ||
} | ||
)); | ||
|
||
/** | ||
* @description - set the user id | ||
* @param {object} user a user | ||
* @param {function} done end of function | ||
* @returns {object} user id | ||
*/ | ||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
|
||
/** | ||
* @description - finds the user by id | ||
* @param {object} user a user | ||
* @param {function} done end of function | ||
* @returns {object} user profile | ||
*/ | ||
passport.deserializeUser(async (id, done) => { | ||
const user = await User.findByPk(id); | ||
return done(null, user); | ||
}); | ||
|
||
export default passport; |
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,27 @@ | ||
require('dotenv').config(); | ||
|
||
const config = { | ||
development: { | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_DATABASE, | ||
host: process.env.DB_HOST, | ||
dialect: 'postgres', | ||
}, | ||
test: { | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_TEST, | ||
host: process.env.DB_HOST, | ||
dialect: 'postgres', | ||
}, | ||
production: { | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_TEST, | ||
host: process.env.DB_HOST, | ||
dialect: 'postgres', | ||
}, | ||
}; | ||
|
||
module.exports = config; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
secret: | ||
process.env.NODE_ENV === "production" ? process.env.SECRET : "secret" | ||
secret: | ||
process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret', | ||
}; |
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
const passport = require("passport"); | ||
const LocalStrategy = require("passport-local").Strategy; | ||
const mongoose = require("mongoose"); | ||
const User = mongoose.model("User"); | ||
const passport = require('passport'); | ||
const LocalStrategy = require('passport-local').Strategy; | ||
const mongoose = require('mongoose'); | ||
|
||
const User = mongoose.model('User'); | ||
|
||
passport.use( | ||
new LocalStrategy( | ||
{ | ||
usernameField: "user[email]", | ||
passwordField: "user[password]" | ||
}, | ||
function(email, password, done) { | ||
User.findOne({ email: email }) | ||
.then(function(user) { | ||
if (!user || !user.validPassword(password)) { | ||
return done(null, false, { | ||
errors: { "email or password": "is invalid" } | ||
}); | ||
} | ||
new LocalStrategy( | ||
{ | ||
usernameField: 'user[email]', | ||
passwordField: 'user[password]', | ||
}, | ||
((email, password, done) => { | ||
User.findOne({ email }) | ||
.then((user) => { | ||
if (!user || !user.validPassword(password)) { | ||
return done(null, false, { | ||
errors: { 'email or password': 'is invalid' }, | ||
}); | ||
} | ||
|
||
return done(null, user); | ||
}) | ||
.catch(done); | ||
} | ||
) | ||
return done(null, user); | ||
}) | ||
.catch(done); | ||
}), | ||
), | ||
); |
Oops, something went wrong.