Commit 098362ce authored by hujun's avatar hujun

登录代码调整

parent 3085f766
......@@ -3,8 +3,7 @@
namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AdminModel;
use app\model\Agents;
use app\model\AAgents;
use app\model\AuthRule;
use think\Session;
......@@ -23,9 +22,8 @@ class Login extends Basic
public function __construct($request = null)
{
parent::__construct($request);
$this->loginAgent=new Agents();
$this->authRule=new AuthRule();
$this->loginDb = new AdminModel();
$this->loginAgent = new AAgents();
$this->authRule = new AuthRule();
}
public function login()
......@@ -42,78 +40,51 @@ class Login extends Basic
*/
public function loginVerify()
{
$name = $_POST["username"];
$passwd = $_POST["passwd"];
if (!isset($name) || !isset($passwd)) {
return view("/login/login", [ "msg" => "用户名或密码不能为空" ]);
}
$params["name"] = $name;
$params["pswd"] = md5($passwd);
$result = $this->loginDb->verifyUser($params);
if (count($result) > 0) {
//todo 更新登录信息
$this->loginDb->updateLoginTime($result[0]["id"]);
Session::set("userName",$result[0]["name"]);
Session::set("userId",$result[0]["id"]);
Session::set("lastLoginTime",time());
$this->operating_records($result[0]["id"],1,'后台登陆'); //记录操作日志
// $this->redirect('/admin.php/index/banner');
// return view("/admin.php/index/banner", [ "msg" => "用户名或密码错误" ]);
return $this->response('200', '登录成功');
} else {
// return view("/login/login", [ "msg" => "用户名或密码错误" ]);
return $this->response('101', '用户名或密码错误');
}
/*$name = $this->request->param("username");
$name = $this->request->param("username");
$password = $this->request->param("passwd");
if (!isset($name) || !isset($password)) {
return $this->response('100','用户名或密码不能为空');
}
$filed=" a.id,a.store_id,a.auth_group_id,a.district_id,a.level,a.name,a.phone,a.sex,a.img,a.status,a.admin_off,
ifnull(s.store_name,'')store_name,ifnull(d.district_name,'')district_name,g.rules,g.status as g_status";
$join=[
['a_store s', ' a.store_id=a.id','left'],
['a_district d','a.district_id=d.id','left'],
['auth_group g','a.auth_group_id=g.id','left']
];
$params["name"] = $name;
$password = md5($password);
$where="( phone='{$name}') and password='$password' ";
$list=$this->loginAgent->verifyUser($filed,$join,$where);
// prt($list->toArray());//转化arr
if(!$list){
if(!$list) {
return $this->response('101','用户名或密码错误');
}
if($list['g_status']=='1'){
if($list['g_status']=='1') {
return $this->response('102','用户所在角色组已冻结');
}
if($list['admin_off']!='0'||empty($list['rules'])){
if($list['admin_off']!='0'||empty($list['rules'])) {
return $this->response('103','用户无后台访问权限');
}else{
$rules=trim($list['rules'],',');
$rules = trim($list['rules'],',');
//查询后台菜单
$where ="id in({$rules})and is_menu=1 and status=0 and pid=1 ";
$nav=$this->authRule->loginRule($where);
$nav2=array();
$url='';//跳转页面
$nav = $this->authRule->loginRule($where);
$nav2 = array();
$url = '';//跳转页面
foreach ($nav as $k=> $v){
if($k=='0'){
$url=$v->name;
if($k == '0'){
$url = $v->name;
}
$nav2[$v->id]=$v;
$nav2[$v->id] = $v;
}
if(!$url){
if(!$url) {
return $this->response('104','用户无任何后台访模块问权限!');
}
//搜索菜单功能
......@@ -121,14 +92,12 @@ class Login extends Basic
$r = $this->authRule->loginRule($where);
$r2 = array();
foreach($r as $v){
$buttonUrl=explode('/',$v->name);
$v['bt']=$buttonUrl[1];
foreach($r as $v) {
$buttonUrl = explode('/',$v->name);
$v['bt'] = $buttonUrl[1];
$r2[$v->pid][] = $v;
}
foreach($nav2 as $k=> $v){
if(!empty($r2[$k])){
$nav2[$k]['cz'] = $r2[$k];
......@@ -137,8 +106,8 @@ class Login extends Basic
$list['nav'] = $nav2;
$list2 = $list->toArray();//转化arr
}
Session::set("userName",$list["name"]);
Session::set("userId",$list["id"]);
Session::set("userinfo",$list2);
......@@ -146,17 +115,14 @@ class Login extends Basic
Session::set("lastLoginTime",time());
$this->operating_records($list["id"],1,'后台登陆'); //记录操作日志
$data['url']=$url;
$data['data']=$list2;
if($this->request->isAjax()) {
return $this->response('200', '登录成功', $data);
}else {
$this->redirect('/admin.php/'.$url);
}*/
// }
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment