<commit_before>var express = require('express');
var router = express.Router();

var util = require("../tools/mysql-query");

/* login. */
router.post('/login', function(req, res, next) {
  var name = req.body.name;
  var pwd = req.body.pwd;
  var sql = 'select * from users where name = "' + name + '" and passwd = "' + pwd + '"';
  util.query(sql).then(function(result){
  	if(result.length > 0){
      req.session.userInfo = {
        userId : result[0].id,
        userName : result[0].name,
        userClass : result[0].class
      };
  		res.end(JSON.stringify({resultCode:"000",userId:result[0].id}));
  	}else{
  		res.end(JSON.stringify({resultCode:"999",msg:"用户不存在!"}));
  	}
  },function(){
  	res.end(JSON.stringify({resultCode:"999",msg:"服务器异常，请稍后再试！"}));
  })

});

/* register. */
router.post('/register', function(req, res, next) {
  var body = req.body;
  var name = body.name;
  if(name.length < 1 || name.length > 10){
    res.end(JSON.stringify({resultCode:"999",msg:"账号长度不符！"}));
    return;
  }
  var pwd = body.pwd;
  if(!/^[a-zA-Z0-9_!@#$%^&*()-\\+]{6,15}$/.test(pwd)){
    res.end(JSON.stringify({resultCode:"999",msg:"密码不符规范！"}));
    return;
  }
  var pwd2 = body.confirm_pwd;
  if(pwd != pwd2){
    res.end(JSON.stringify({resultCode:"999",msg:"两次输入的密码不一致！"}));
    return;
  }
  var sql = 'insert into users(name,passwd,date) values ("' + name + '", "' + pwd + '",' + new Date().getTime() + ')';
  util.insert(sql).then(function(result){
    res.end(JSON.stringify({resultCode:"000",msg:"注册成功！"}));
  },function(err){
    res.end(JSON.stringify({resultCode:"999",msg:"服务器异常，请稍后再试！"}));
  })

});




module.exports = router;<commit_msg>调整登录验证语<commit_after>var express = require('express');
var router = express.Router();

var util = require("../tools/mysql-query");

/* login. */
router.post('/login', function(req, res, next) {
  var name = req.body.name;
  var pwd = req.body.pwd;
  var sql = 'select * from users where name = "' + name + '" and passwd = "' + pwd + '"';
  util.query(sql).then(function(result) {
    if (result.length > 0) {
      req.session.userInfo = {
        userId: result[0].id,
        userName: result[0].name,
        userClass: result[0].class
      };
      res.end(JSON.stringify({
        resultCode: "000",
        userId: result[0].id
      }));
    } else {
      res.end(JSON.stringify({
        resultCode: "999",
        msg: "账号或密码错误！"
      }));
    }
  }, function() {
    res.end(JSON.stringify({
      resultCode: "999",
      msg: "服务器异常，请稍后再试！"
    }));
  });

});

/* register. */
router.post('/register', function(req, res, next) {
  var body = req.body;
  var name = body.name;
  if (name.length < 1 || name.length > 10) {
    res.end(JSON.stringify({
      resultCode: "999",
      msg: "账号长度不符！"
    }));
    return;
  }
  var pwd = <PASSWORD>;
  if (!/^[a-zA-Z0-9_!@#$%^&*()-\\+]{6,15}$/.test(pwd)) {
    res.end(JSON.stringify({
      resultCode: "999",
      msg: "密码不符规范！"
    }));
    return;
  }
  var pwd2 = body.confirm_pwd;
  if (pwd != pwd2) {
    res.end(JSON.stringify({
      resultCode: "999",
      msg: "两次输入的密码不一致！"
    }));
    return;
  }
  var sql = 'insert into users(name,passwd,date) values ("' + name + '", "' + pwd + '",' + new Date().getTime() + ')';
  util.insert(sql).then(function(result) {
    res.end(JSON.stringify({
      resultCode: "000",
      msg: "注册成功！"
    }));
  }, function(err) {
    res.end(JSON.stringify({
      resultCode: "999",
      msg: "服务器异常，请稍后再试！"
    }));
  });

});



module.exports = router;
{'fraction_non_alphanumeric': 0.21998867497168742, 'fraction_numerical': 0.022083805209513023, 'mean_word_length': 2.9168514412416853, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4969045', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1435, 'n_words': 219}