fixed auth, fallback, and pages routes

This commit is contained in:
bill bittner 2018-03-29 11:40:47 -07:00
parent 9523890b65
commit c67a25ca2c
15 changed files with 81 additions and 84 deletions

View file

@ -1,11 +1,12 @@
const signup = require('./signup');
const login = require('./login');
const logout = require('./logout');
const user = require('./user');
const speechPassport = require('speechPassport');
const handleSignupRequest = require('./signup');
const handleLoginRequest = require('./login');
const handleLogoutRequest = require('./logout');
const handleUserRequest = require('./user');
module.exports = {
signup,
login,
logout,
user,
module.exports = (app) => {
app.post('/signup', speechPassport.authenticate('local-signup'), handleSignupRequest);
app.post('/login', handleLoginRequest);
app.get('/logout', handleLogoutRequest);
app.get('/user', handleUserRequest);
};

View file

@ -1,6 +1,7 @@
const login = (passport) => {
return (req, res, next) => {
passport.authenticate('local-login', (err, user, info) => {
const speechPassport = require('speechPassport');
const login = (req, res, next) => {
speechPassport.authenticate('local-login', (err, user, info) => {
if (err) {
return next(err);
}
@ -23,6 +24,5 @@ const login = (passport) => {
});
})(req, res, next);
};
};
module.exports = login;

View file

@ -1,8 +1,6 @@
const logout = () => {
return (req, res) => {
const logout = (req, res) => {
req.logout();
res.status(200).json({success: true, message: 'you successfully logged out'});
};
};
module.exports = logout;

View file

@ -1,5 +1,4 @@
const signup = () => {
return (req, res) => {
const signup = (req, res) => {
res.status(200).json({
success : true,
channelName : req.user.channelName,
@ -7,6 +6,5 @@ const signup = () => {
shortChannelId: req.user.shortChannelId,
});
};
};
module.exports = signup;

View file

@ -1,11 +1,9 @@
const user = () => {
return (req, res) => {
const user = (req, res) => {
if (req.user) {
res.status(200).json({success: true, data: req.user});
} else {
res.status(401).json({success: false, message: 'user is not logged in'});
}
};
};
module.exports = user;

View file

@ -0,0 +1,5 @@
const handlePageRequest = require('./sendReactApp');
module.exports = (app) => {
app.get('*', handlePageRequest);
};

View file

@ -0,0 +1,7 @@
const handlePageRender = require('helpers/handlePageRender.jsx');
const sendReactApp = (req, res) => {
handlePageRender(req, res);
};
module.exports = sendReactApp;

View file

@ -1,11 +1,13 @@
const sendReactApp = require('./sendReactApp');
const sendEmbedPage = require('./sendEmbedPage');
const handlePageRequest = require('./sendReactApp');
const handleEmbedRequest = require('./sendEmbedPage');
const redirect = require('./redirect');
module.exports = {
sendReactApp,
sendEmbedPage,
redirect,
module.exports = (app) => {
app.get('/', handlePageRequest);
app.get('/login', handlePageRequest);
app.get('/about', handlePageRequest);
app.get('/trending', redirect('/popular'));
app.get('/popular', handlePageRequest);
app.get('/new', handlePageRequest);
app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter)
};

View file

@ -1,12 +1,10 @@
const { details: { host } } = require('siteConfig.js');
const sendEmbedPage = () => {
return ({ params }, res) => {
const sendEmbedPage = ({ params }, res) => {
const claimId = params.claimId;
const name = params.name;
// get and render the content
res.status(200).render('embed', { layout: 'embed', host, claimId, name });
};
};
module.exports = sendEmbedPage;

View file

@ -1,9 +1,7 @@
const handlePageRender = require('helpers/handlePageRender.jsx');
const sendReactApp = () => {
return (req, res) => {
const sendReactApp = (req, res) => {
handlePageRender(req, res);
};
};
module.exports = sendReactApp;

View file

@ -4,11 +4,8 @@ const bodyParser = require('body-parser');
const expressHandlebars = require('express-handlebars');
const Handlebars = require('handlebars');
const helmet = require('helmet');
const passport = require('passport');
const { serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const cookieSession = require('cookie-session');
const http = require('http');
// logging dependencies
const logger = require('winston');
function Server () {
@ -41,20 +38,15 @@ function Server () {
});
// configure passport
passport.serializeUser(serializeSpeechUser);
passport.deserializeUser(deserializeSpeechUser);
const localSignupStrategy = require('./passport/local-signup.js');
const localLoginStrategy = require('./passport/local-login.js');
passport.use('local-signup', localSignupStrategy);
passport.use('local-login', localLoginStrategy);
const speechPassport = require('speechPassport');
// initialize passport
app.use(cookieSession({
name : 'session',
keys : [this.sessionKey],
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(speechPassport.initialize());
app.use(speechPassport.session());
// configure handlebars & register it with express app
const hbs = expressHandlebars.create({
@ -80,7 +72,7 @@ function Server () {
this.server = http.Server(this.app);
};
this.start = () => {
const db = require('./models/index');
const db = require('./models/');
// sync sequelize
db.sequelize.sync()
// start the server

View file

@ -11,7 +11,7 @@ const logger = require('./config/loggerConfig.js');
const mysql = require('./config/mysqlConfig');
const site = require('./config/siteConfig');
const slack = require('./config/slackConfig.js');
const passport = require('./server/passport/');
const passport = require('./server/speechPassport/');
const models = require('./server/models/');
const exports = {