nodejs指南操作,注册页面出错
发布于 8 年前 作者 owen-hong 4419 次浏览 最后一次编辑是 6 年前

Express 500 ReferenceError: reg is not defined at exports.doReg (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\routes\index.js:58:31) at callbacks (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\lib\router\index.js:164:37) at param (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\lib\router\index.js:138:11) at pass (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\lib\router\index.js:145:5) at Router._dispatch (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\lib\router\index.js:173:5) at Object.router (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\lib\router\index.js:33:10) at next (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\node_modules\connect\lib\proto.js:193:15) at Object.handle (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\app.js:65:6) at next (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\node_modules\connect\lib\proto.js:193:15) at next (C:\Users\Administrator.B45N8CRM69I280E\Desktop\weiyun\NodeJs\UED\node_modules\express\node_modules\connect\lib\middleware\session.js:315:9)


报错如上提示,我注册写的代码如下: exports.reg = function(req, res){ res.render(‘reg’, { title: ‘用户注册’, user : req.session.user, success : req.flash(‘success’).toString(), error : req.flash(‘error’).toString() }); };

exports.doReg = function(req, res){ //检查密码 if (req.body[‘password-repeat’] != req.body[‘password’]) { req.flash(‘error’, ‘两次输入的密码不一致’); return res.redirect(’/reg’); }

//生成口令的散列值
var md5 = crypto.createHash('md5');
var password = md5.update(reg.body.password).digest('base64');

var newUser = new User({
 name : req.body.username,
 password : password,
});

//检查用户名是否已经存在
User.get(newUser.name,function(err,user){
 if(user)
  err = '用户名已经存在';
 if(err){
  req.flash('error',err);
  return res.redirect('/reg')
 }
 //如果不存在则新增用户
 newUser.save(function(err){
  if(err){
   req.flash('error',err);
   return res.redirect('/reg');
  }
  req.session.user = new newUser;
  req.flash('success','注册成功');
  res.redirect('/');
 });
});

};

代码都是按照书上的搞,但是注册这块还有flash(error)都没报错,坑爹很,求各位大神解答啊。

2 回复

此问题已解决,谢谢

这个怎么解决的啊  遇到一样的问题

回到顶部