res.render函数不起作用

时间:2017-10-24 14:58:12

标签: node.js express

我正在尝试渲染到错误页面,如果电子邮件未确认但res.render功能不起作用,并且在浏览器控制台中显示已加载 代码是

const connection = require('../DBconnection/database');
const bcrypt      = require('bcryptjs');

module.exports.login = function(req,res){
  var email = req.body.email;
  var password = req.body.password;
  connection.query('SELECT * FROM user_registration WHERE email = ?',email,(error,rows,fields)=>{
    if(error){
      console.log(error);
      res.json({message:'Oops!! something wrong happned',status:false})}else{
      if(rows.length <= 0){
        res.json({message:'This email is not registered.',status:false});
      }else{
        var hash = rows[0].password;
        var compare = bcrypt.compareSync(password,hash);
        if(compare){
          if(rows[0].unique_id == '0'){
            console.log('commotnsdafads');
            res.render('error.ejs',{code:'unvarified_email',title:'email varification'});
            res.end();
          }else{
          req.session.unique_id = rows[0].unique_id;
          req.session.username  = rows[0].username;
          req.session.email      = rows[0].email;
          req.session.profileurl = rows[0].userimage;
          res.json({message:'login successfull.',status:true,unique_id:req.session.unique_id});
          }
        }else{
          res.json({message:'password did not matched',status:false});
        }
      }
    }
  })
}

module.exports.logout = function(req,res) {
  req.session.destroy();
  res.json({status:true,message:'logout successfull'});
}

提前致谢。

0 个答案:

没有答案