Commit b2d7c537 authored by hujun's avatar hujun

登录优化

parent eaa06b05
......@@ -231,7 +231,7 @@ return [
// 是否自动开启 SESSION
'auto_start' => true,
//过期时间
'expire' => 36000
'expire' => 7200
],
// +----------------------------------------------------------------------
......
......@@ -11,6 +11,7 @@ use app\model\ASite;
use app\model\AStore;
use app\model\AuthGroup;
use app\model\AuthRule;
use think\Config;
use think\Session;
/**
......@@ -163,8 +164,10 @@ class Login extends Basic
$jwt_data['level'] = $user_data['level'];
$user_data['AuthToken'] = $jwt->createToken($jwt_data);
$expire_time = Config::get('session.expire') + time() - 30;
Session::set("userName", $user_data["name"]);
Session::set("userId", $user_data["id"]);
Session::set("expire_time", $expire_time);
Session::set("lastLoginTime", time());
Session::set("user_info", $user_data);
$this->operating_records($user_data["id"], 1, '后台登陆'); //记录操作日志
......
......@@ -14,7 +14,9 @@ use app\model\AAgents;
use app\model\GHousesToAgents;
use app\model\GOperatingRecords;
use app\model\Users;
use think\Config;
use think\Controller;
use think\Cookie;
use think\Request;
use think\Response;
use think\Session;
......@@ -35,6 +37,7 @@ class Basic extends Controller
public $userId;
public $expire_time;
public $lastLoginTime;
public $city;
......@@ -228,7 +231,7 @@ class Basic extends Controller
if (empty($is_auth) && $this->userId != 1) {
if($this->request->isAjax()){
echo json_encode(array( "code" => "300", "msg" => "没有权限!", "data" => [], "type" => "json" ));exit;
echo json_encode(array( "code" => "301", "msg" => "没有权限!", "data" => [], "type" => "json" ));exit;
} else {
$this->error('没有当前页面权限');exit;
}
......@@ -243,27 +246,20 @@ class Basic extends Controller
*/
public function userVerify(){
$this->lastLoginTime = Session::get("lastLoginTime");
if(empty($this->userName) || empty($this->userId) || empty($this->lastLoginTime) ){
$this->expire_time = Session::get("expire_time");
if(empty($this->lastLoginTime)){
if ($this->request->isAjax()) {
echo json_encode(array( "code" => "101", "msg" => "登录失效,请重新登录", "data" => [], "type" => "json" ));exit;
echo json_encode(array( "code" => "300", "msg" => "登录失效,请重新登录", "data" => [], "type" => "json" ));exit;
} else {
$this->redirect('/index/login');
}
}
$time = time();
//登录有效期判断
if (($time - $this->lastLoginTime) > 36000) {
if ($this->request->isAjax()) {
echo json_encode(array( "code" => "101", "msg" => "登录失效,请重新登录", "data" => [], "type" => "json" ));exit;
} else {
$this->redirect('/index/login');die;
if ($this->expire_time < time()) {
$expire = Config::get('session.expire');
$expire = empty($expire) ? 7200 : $expire;
Cookie::set('PHPSESSID', session_id(), $expire); //更新session_id过期时间
}
} else {
//更新时间
Session::set("lastLoginTime", $time);
}
return ;
}
......
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