Commit 03ed22ee authored by zfcaa's avatar zfcaa Committed by zfc

登录

parent 5e43b422
......@@ -5,6 +5,7 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\AdminModel;
use app\model\AuthRule;
use think\Request;
use think\Session;
......@@ -20,11 +21,13 @@ class Login extends Basic
protected $loginDb;
protected $loginagent;
protected $authrule;
public function __construct($request = null)
{
parent::__construct($request);
$this->loginDb = new AdminModel();
$this->loginagent=new AAgents();
$this->authrule=new AuthRule();
}
public function login()
......@@ -61,9 +64,54 @@ class Login extends Basic
return view("/login/login", [ "msg" => "用户名或密码错误" ]);
}
}else{
//条件
$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";
$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;
$params["pswd"] = md5(md5($passwd));
$this->loginagent->verifyUser($params);
$passwd = md5($passwd);
$where="(name='{$name}'or phone='{$name}') and password='$passwd' ";
$list=$this->loginagent->verifyUser($field,$join,$where);
if(!$list){
return view("/login/login", [ "msg" => "用户名或密码错误" ]);
}
//prt($list->toArray());//转化arr
if($list['admin_off']!='0'||empty($list['rules'])){
return view("/login/login", [ "msg" => "用户无后台访问权限" ]);
}else{
$rules=trim($list['rules'],',');
$where ="id in({$rules})and is_menu=1 and status=1 and pid=1 ";
$list['nav']=$this->authrule->loginRule($where);
foreach($list['nav'] as $k=> $v){
// prt($v->toArray());
$where ="pid='{$v['id']}' and id in({$rules}) and is_menu=0 and status=1 ";
$r= $this->authrule->loginRule($where);
if($r){
// prt($r);
// // prt($r->toArray());//转化arr
// exit;
$list['rules'][$k]['cz']=$r;
}
}
prt($list->toArray());//转化arr
exit;
}
Session::set("userName",$list["name"]);
Session::set("userId",$list["id"]);
Session::set("userinfo",$list);
Session::set("lastLoginTime",time());
$this->operating_records($result[0]["id"],1,'后台登陆'); //记录操作日志
$this->redirect('/admin.php/index/banner');
}
......
......@@ -107,11 +107,16 @@ public function saveList(){
return $data;
}
public function verifyUser($params)
public function verifyUser($field,$join,$params)
{
return $this->db
$r= $this->field($field)
->alias('a')
->join($join)
->where($params)
->select();
->find();
// echo $this->getLastSql();
return $r;
}
}
\ No newline at end of file
......@@ -106,5 +106,15 @@ class AuthRule extends BaseModel
return false;
}
}
public function loginRule($where){
$r=$this->field('id,name,title')
->where($where)
->select();
$this->getLastSql();
return $r;
}
}
\ No newline at end of file
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