var models = require('../models');

exports.log_in_check = function(req,res){
  console.log("inlogin");
  console.log(req.body);

  var email = req.body.email;
  var filter = /^([a-zA-Z0-9_\.\-])+\@ucsd.edu+$/;
  var password = req.body.password;
  var errorMsgs = ["nopwd","invalidemail","noaccount","wrongpwd"];
  var error = "";

  if (!filter.test(email)){
  	    error = errorMsgs[1];
  	    res.send(error);
  }else if (password == ''){
  	    error = errorMsgs[0];
  	    res.send(error);
  }else{
	models.User
    	.find({"email": email})
    	.sort()
    	.exec(checkUser);

    function checkUser(err, users){
    	if(err) console.log(err);
    	if(!users){//not found user
          error = errorMsgs[2];
          res.send(error);
    	}else{
    	  console.log("that="+users[0]);
    	  if(users[0].pwd != password){
            error = errorMsgs[3];
            res.send(error);
    	  }else{
    	  	error = users[0]._id;
    	  	res.send(error);
    	  }
    	}
	}
  }	
}
@@ -670,24 +670,61 @@
 (err);%0D%0A
+    %09console.log(%22isHERE%22 + users);%0D%0A
     %09if(
 !users)%7B
@@ -719,14 +719,29 @@
 %09if(
-!
 users
+%5B0%5D == undefined
 )%7B//

fix the bug of account does not exist