node.js - Node/Express/Jade passing username back to view -
this first project these technologies, typically angular, working charity ( , keen learn node ). day three.
during login, method called:
schema.statics.authenticateandload = function(req, res, next) { var userid = req.body.email; res.locals.userid = userid;
this supposed store value doesn't need reentered. if login fails, this:
return next('login failed. please enter details , try again.');
then in jade template:
if(locals.userid) p welcome #{userid} else p welcome
the actual template has code try want:
input(type='text', name='email', id="inputemail", placeholder="email", value="#{body.email || ''}")
but not work.
so, think means setting value in result lost when call 'next', but, because it's passing in error object show on screen, i'm not sure how go making sure error shows , make value pass through . right now, text says 'welcome' , never 'welcome xx', test code, i'm proving value not being passed through.
my question is, what's correct way pass value through template, , trigger error message being shown.
the code, when step in it, goes deep in express , checks errors there.
hi see developers doing charity work.
typically use assuming piece of middleware
schema.statics.authenticateandload = function(req, res, next) { var userid = req.body.email; res.locals.userid = userid; loginfunction(userdetails,function(error,result){ //if there error need render page or redirect //login page if(error){ var msg = 'login failed. please enter details , try again.' return res.render('login',{userid: userid,error: msg}) //this renders login page , passes req.body.email page userid , msg error } if(result){ //if correct return next() saying //you may go through return next() } } }
then on jade display error use , userid
p #{userid} p #{error}
so answer question correct way send value jade pass in using , pass error in variable.
return res.render(template_name,{userid: req.body.email,error: msg})
i hope helps out
Comments
Post a Comment