Created
March 9, 2013 19:52
-
-
Save Willmo36/5125498 to your computer and use it in GitHub Desktop.
JavaScript example. Controller in for a NodeJS app.
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
var userController = module.exports = { | |
register:function (req, res, next) { | |
var postValues = req.body; | |
var newUser = new userModel(); | |
newUser.saveAndGetErrors(postValues, function(user){ | |
req.session.loggedIn = true; | |
req.session.userId = user._id; | |
if(req.body.returnUrl) res.redirect(res.body.returnUrl); | |
else res.render("/user/profile", {user:user}); | |
}, | |
function(validationErrors){ | |
res.render('/user/create',{validationErrors:validationErrors}); | |
}) | |
}, | |
update:function (req, res, next) { | |
throw new Error('Not implemented'); | |
}, | |
delete:function (req, res, next) { | |
throw new Error('Not implemented'); | |
}, | |
login:function (req, res, next) { | |
var loggedIn = userModel.user.model.login(req.username, req.password); | |
if (loggedIn) res.redirect(req.body.targetUrl); | |
else res.render('/home/login', {failed:true}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment