p5.js-web-editor/server/controllers/session.controller.js

35 lines
752 B
JavaScript
Raw Normal View History

2016-06-14 20:48:16 +00:00
import User from '../models/user'
import passport from 'passport'
import path from 'path'
export function destroySession(req, res) {
}
export function createSession(req, res, next) {
passport.authenticate('local', (err, user, info) => {
if (err) { return next(err); }
if (!user) {
return res.status(401).send({ error: 'Invalid username or password' });
}
req.logIn(user, (err) => {
if (err) { return next(err); }
res.json({
email: req.user.email,
username: req.user.username
});
});
})(req, res, next);
}
export function getSession(req, res, next) {
if (req.user) {
return res.json({
email: req.user.email,
username: req.user.username
});
}
res.status(404).send({message: 'Session does not exist'});
2016-06-14 20:48:16 +00:00
}