-
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.
feat(notification): Send notification to users
- write unit test - send email notification to users - create database on firebase - set up firebase configuration - populate database with user notifications [Delivers #159206059]
- Loading branch information
Showing
41 changed files
with
1,862 additions
and
450 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
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 |
---|---|---|
|
@@ -39,3 +39,5 @@ dist/ | |
# enviroment variables | ||
.env | ||
|
||
#txt | ||
txt.txt |
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,31 +1,51 @@ | ||
import passport from 'passport'; | ||
import bcrypt from 'bcrypt'; | ||
import local from 'passport-local'; | ||
import db from '../models'; | ||
import GoogleStrategy from 'passport-google-oauth20'; | ||
import FacebookStrategy from 'passport-facebook'; | ||
import AuthController from '../controllers/authController'; | ||
import { User } from '../models'; | ||
|
||
const LocalStrategy = local.Strategy; | ||
|
||
passport.use(new LocalStrategy( | ||
{ | ||
usernameField: 'user[email]', | ||
passwordField: 'user[password]' | ||
}, | ||
((email, password, done) => { | ||
db.User.findOne({ where: { email } }) | ||
.then((user) => { | ||
bcrypt.compare( | ||
password, | ||
user.hashedPassword, | ||
(err, res) => { | ||
if (!user || !res || err) { | ||
return done(null, false, { | ||
errors: { 'email or password': 'is invalid' } | ||
}); | ||
} | ||
return done(null, user); | ||
const passportConfig = (app) => { | ||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
passport.use(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' } | ||
}); | ||
} | ||
); | ||
}) | ||
.catch(done); | ||
}) | ||
)); | ||
|
||
return done(null, user); | ||
}) | ||
.catch(done); | ||
}) | ||
)); | ||
|
||
/** | ||
* configurations for passport strategies | ||
*/ | ||
|
||
passport.use(new GoogleStrategy({ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: '/api/users/login/google/redirect', | ||
}, AuthController.strategyCallback)); | ||
|
||
passport.use(new FacebookStrategy({ | ||
clientID: process.env.FACEBOOK_APP_ID, | ||
clientSecret: process.env.FACEBOOK_APP_SECRET, | ||
callbackURL: '/api/users/login/facebook/redirect', | ||
profileFields: ['id', 'displayName', 'photos', 'email'], | ||
}, AuthController.strategyCallback)); | ||
}; | ||
|
||
export default passportConfig; |
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
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,98 @@ | ||
import { User } from '../models'; | ||
import utilities from '../helpers/utilities'; | ||
/** | ||
* @class AuthController | ||
* | ||
* @export | ||
* | ||
*/ | ||
export default class AuthController { | ||
/** | ||
* @description - json response function | ||
* @static | ||
* | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* | ||
* @returns {json} json | ||
* | ||
* @memberof AuthController | ||
* | ||
*/ | ||
static jsonResponse(req, res) { | ||
const user = { | ||
email: req.user.email, | ||
token: utilities.signToken({ id: req.user.id }), | ||
firstname: req.user.firstname, | ||
lastname: req.user.lastname, | ||
username: req.user.username, | ||
image: req.user.image, | ||
}; | ||
if (req.user.created) { | ||
return res.status(201).json({ success: true, user }); | ||
} | ||
return res.status(200).json({ success: true, user }); | ||
} | ||
|
||
/** | ||
* @description - model query function | ||
* @static | ||
* | ||
* | ||
* @param {object} user | ||
* @param {function} done | ||
* | ||
* @returns {object} newOrFoundUser | ||
* | ||
* @memberof AuthController | ||
* | ||
*/ | ||
static queryModel(user, done) { | ||
User.findOrCreate({ | ||
where: { | ||
email: user.email, | ||
}, | ||
defaults: user, | ||
}).spread((newOrFoundUser, created) => { | ||
const { | ||
id, email, username, lastname, firstname, image, | ||
} = newOrFoundUser.dataValues; | ||
return done(null, { | ||
id, | ||
email, | ||
username, | ||
lastname, | ||
firstname, | ||
image, | ||
created, | ||
}); | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* @description - strategy callback function | ||
* @static | ||
* | ||
* @param {object} accessToken | ||
* @param {object} refreshToken | ||
* @param {object} profile | ||
* @param {function} done | ||
* | ||
* @returns {json} json | ||
* | ||
* @memberof AuthController | ||
* | ||
*/ | ||
static strategyCallback(accessToken, refreshToken, profile, done) { | ||
const userProfile = { | ||
firstname: profile.name.familyName, | ||
lastname: profile.name.givenName, | ||
username: profile.id, | ||
email: profile.emails[0].value, | ||
image: profile.photos[0].value, | ||
}; | ||
AuthController.queryModel(userProfile, done); | ||
} | ||
} |
File renamed without changes.
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
Oops, something went wrong.