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

30 lines
647 B
JavaScript
Raw Normal View History

import User from '../models/user'
import passport from 'passport'
import path from 'path'
export function createUser(req, res, next) {
const user = new User({
username: req.body.username,
email: req.body.email,
password: req.body.password
});
User.findOne({email: req.body.email}, (err, existingUser) => {
if (existingUser) {
2016-06-09 17:56:23 +00:00
return res.status(422).send({ error: 'Email is in use' });
}
user.save((err) => {
if (err) { return next(err); }
req.logIn(user, (err) => {
if (err) {
return next(err);
}
2016-06-14 18:46:40 +00:00
res.json({
email: req.user.email,
username: req.user.username
});
});
});
});
}