This file contains hidden or 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
| // | |
| // Smooth scroll-to inspired by: | |
| // http://stackoverflow.com/a/24559613/728480 | |
| // | |
| module.exports = function (scrollTo, scrollDuration) { | |
| // | |
| // Set a default for where we're scrolling to | |
| // |
This file contains hidden or 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
| { | |
| "dependencies": { | |
| "@koa/cors": "^2.2.1", | |
| "axios": "^0.18.0", | |
| "bcrypt": "^2.0.0", | |
| "bootstrap": "^4.1.0", | |
| "classnames": "^2.2.5", | |
| "dotenv": "^6.0.0", | |
| "find-config": "^1.0.0", | |
| "jquery": "^3.3.1", |
This file contains hidden or 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
| require('dotenv').config({ path: require('find-config')('.env') }); | |
| const Koa = require('koa'); | |
| const Router = require('koa-router'); | |
| const koaLogger = require('koa-logger'); | |
| const cors = require('@koa/cors'); | |
| const bodyParser = require('koa-bodyparser'); | |
| const serve = require('koa-static'); | |
| const send = require('koa-send'); | |
| const path = require('path'); | |
| const session = require('koa-session'); |
This file contains hidden or 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
| // create mock database with one user | |
| const db = redis.createClient(); | |
| db.on('error', (err) => { | |
| console.log(`Redis Error ${err}`); | |
| }); | |
| db.set('usersMockDatabase', JSON.stringify([ | |
| { | |
| id: 1, | |
| email: 'chouomam@chouman.com', | |
| // "test" -- generated by bcrypt calculator |
This file contains hidden or 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
| const auth = require('./controllers/auth'); | |
| const router = new Router(); | |
| router | |
| /* Handle Login POST */ | |
| .post('/login', ctx => passport.authenticate('local', (err, user) => { | |
| if (!user) { | |
| ctx.throw(401, err); | |
| } else { | |
| ctx.body = user; |
This file contains hidden or 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
| const bcrypt = require('bcrypt'); | |
| const passport = require('koa-passport'); | |
| const FacebookStrategy = require('passport-facebook').Strategy; | |
| const LocalStrategy = require('passport-local').Strategy; | |
| const config = require('../serverConfig'); | |
| const { db } = require('../server'); | |
| const { promisify } = require('util'); | |
| const getAsync = promisify(db.get).bind(db); |
This file contains hidden or 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
| passport.use( | |
| new LocalStrategy( | |
| { | |
| usernameField: 'email', | |
| passwordField: 'password', | |
| }, | |
| async (email, password, done) => { | |
| let user = null; | |
| await getAsync('usersMockDatabase').then((users) => { | |
| const currUsers = JSON.parse(users); |
This file contains hidden or 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
| passport.use( | |
| new FacebookStrategy( | |
| { | |
| clientID: config.facebookAuth.clientID, | |
| clientSecret: config.facebookAuth.clientSecret, | |
| callbackURL: config.facebookAuth.callbackURL, | |
| profileFields: [ | |
| 'id', | |
| 'displayName', | |
| 'picture.width(200).height(200)', |
This file contains hidden or 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
| exports.getLoggedUser = async (ctx) => { | |
| if (ctx.isAuthenticated()) { | |
| const reqUserId = ctx.req.user.id; | |
| let user = null; | |
| await getAsync('usersMockDatabase').then((users) => { | |
| user = JSON.parse(users).find(currUser => currUser.id === reqUserId); | |
| }); | |
| if (user) { | |
| delete user.password; | |
| ctx.response.body = user; |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>AUTH FLOW</title> | |
| <meta name="description" content=""> | |
| <!-- Mobile-friendly viewport --> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| </head> | |
| <body> |