fetch(); } /** * 处理登录 */ public function do_login(){ if(Request::instance()->post()){ // 接收表单提交过来的数据,做数据验证 $username = Request::instance()->post('name'); $password = Request::instance()->post('password'); if(!isset($username) || empty($username)){ die(json_encode(['code'=>0,'msg'=>'用户名不能为空!'])); } if(!isset($password) || empty($password)){ die(json_encode(['code'=>0,'msg'=>'密码不能为空!'])); } // 查询客户信息,判断用户名和密码是否正确 $admin_info = Db::name('user')->where('username',$username)->where('agent',2)->find(); if(empty($admin_info)){ die(json_encode(['code'=>0,'msg'=>'用户不存在!'])); } if(think_ucenter_md5($password,UC_AUTH_KEY) != $admin_info['password']){ die(json_encode(['code'=>0,'msg'=>'密码错误!'])); } if(!$admin_info['login_token']){ $admin_info['login_token'] = md5($admin_info['encrypt'].$admin_info['password']); Db::name('user')->where('username',$username)->where('agent',2)->update(['login_token' => $admin_info['login_token']]); } Session::set('user_info',$admin_info); die(json_encode(['code'=>1,'msg'=>'登录成功!','url'=>'/'])); }else{ die(json_encode(['code'=>0,'msg'=>'操作错误!'])); } } public function logout(){ Session::set('user_info',""); $this->redirect('/login/index',302); } }