验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
gistfile1.txt
原始数据 复制代码
//判断用户名和密码是否正确
if (empty($result)) {
echo json_encode(['code' => '001', 'msg' => '用户名或密码不正确']);die;
// $this->error->show_error(['msg' => '用户名或密码不正确', 'url' => 'login', 'wait' => 2]);
}
//判断验证码是否正确
if ( $_SESSION['captcha'] != $code ) {
echo $_SESSION['captcha'].'---'.$code.'<br>';
echo json_encode(['code' => '002', 'msg' => '验证码错误']);die;
// $this->error->show_error(['msg' => '验证码错误', 'url' => 'login', 'wait' => 2]);
}
//把数据存入redis
if (!$this->link) {
echo json_encode(['code' => '003', 'msg' => '连接redis失败']);die;
// $this->error->show_error(['msg' => '连接redis失败,请查看是否开启', 'url' => 'login', 'wait' => 5]);
} else {
//生成token, 作为存储的键 算法 :md5(用户名)+密码
$token = md5($result['name']).$result['password'];
// echo $token;die;
$this->redis->set('id', $result['id']);
$this->redis->hset($token, 'name', $result['name']);
$this->redis->hset($token, 'password', $result['password']);
echo json_encode(['token' => $token,'code' => '000', 'msg' => '登录成功']);die;
}
/*--------------客户端代码-------------*/
function dosubmit(){
var name = $('#name').val();
var password = $('#password').val();
var code = $('#code').val();
$.post('<?= $this->router->url('check_login')?>', {name:name, password:password, code:code}, function(data){
url = "<?= $this->router->url('stu');?>";
if (data.token != null) {
$.cookie('token', data.token, {expires:7});
location = url;
} else {
alert(data.msg);
}
})
return false;
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助