Commit b2d7c537 authored by hujun's avatar hujun

登录优化

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