Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created March 9, 2013 19:52
Show Gist options
  • Save Willmo36/5125498 to your computer and use it in GitHub Desktop.
Save Willmo36/5125498 to your computer and use it in GitHub Desktop.
JavaScript example. Controller in for a NodeJS app.
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