From a5c41c71af65ba90340f74254c5b3876cd7ebdfe Mon Sep 17 00:00:00 2001 From: Devil Date: Thu, 15 Apr 2021 10:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 2 +- application/service/ResourcesService.php | 24 +++++++++ config/app.php | 2 +- extend/base/Verify.php | 51 +++++++++++++++---- .../common/lib/ueditor/dialogs/map/map.html | 2 +- .../common/lib/ueditor/dialogs/map/show.html | 2 +- 6 files changed, 69 insertions(+), 14 deletions(-) diff --git a/application/common.php b/application/common.php index ec144e82b..e71c36918 100755 --- a/application/common.php +++ b/application/common.php @@ -94,7 +94,7 @@ function GetUrlHost($url) } // 判断是否是双后缀 - $preg = '/[\w].+\.(com|net|org|gov|ac|bj|sh|tj|cq|he|sn|sx|nm|ln|jl|hl|js|zj|ah|fj|jx|sd|ha|hb|hn|gd|gx|hi|sc|gz|yn|gs|qh|nx|xj|tw|hk|mo|xz|edu|ge|dev)\.cn$/'; + $preg = '/[\w].+\.(com|net|org|gov|ac|bj|sh|tj|cq|he|sn|sx|nm|ln|jl|hl|js|zj|ah|fj|jx|sd|ha|hb|hn|gd|gx|hi|sc|gz|yn|gs|qh|nx|xj|tw|hk|mo|xz|edu|ge|dev|co)\.(cn|nz)$/'; if(($n > 2) && preg_match($preg, $host)) { // 双后缀取后3位 diff --git a/application/service/ResourcesService.php b/application/service/ResourcesService.php index 7e9388549..0b8716c2d 100755 --- a/application/service/ResourcesService.php +++ b/application/service/ResourcesService.php @@ -12,6 +12,7 @@ namespace app\service; use think\Db; use think\facade\Hook; +use app\service\UserService; /** * 资源服务层 @@ -672,5 +673,28 @@ class ResourcesService 'application/x-zip-compressed', ]; } + + /** + * 获取用户唯一id + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-04-15 + * @desc 未登录取[uuid]前端传过来的uuid、已登录取[用户id]、都没有则返回空字符串 + */ + public static function UserUniqueId() + { + // 取参数uuid、默认空 + $uid = input('uuid', ''); + + // 用户信息 + $user = UserService::LoginUserInfo(); + if(!empty($user) && !empty($user['id'])) + { + $uid = $user['id']; + } + + return empty($uid) ? '' : md5($uid); + } } ?> \ No newline at end of file diff --git a/config/app.php b/config/app.php index 726db50bb..6d3a2b114 100755 --- a/config/app.php +++ b/config/app.php @@ -19,7 +19,7 @@ return [ // 应用地址 'app_host' => '', // 应用调试模式 - 'app_debug' => false, + 'app_debug' => true, // 应用Trace 'app_trace' => false, // 是否支持多模块 diff --git a/extend/base/Verify.php b/extend/base/Verify.php index de6c0215e..90f2dca4c 100755 --- a/extend/base/Verify.php +++ b/extend/base/Verify.php @@ -10,6 +10,8 @@ // +---------------------------------------------------------------------- namespace base; +use app\service\ResourcesService; + /** * 验证码驱动 * @author Devil @@ -30,6 +32,7 @@ class Verify private $use_text_color_back; private $key_verify; private $expire_time; + private $user_uid; /** * [__construct 构造方法] @@ -62,6 +65,9 @@ class Verify $this->use_text_color_back = isset($param['use_text_color_back']) ? $param['use_text_color_back'] : in_array('textcolor', $rules); $this->key_verify = isset($param['key_prefix']) ? trim($param['key_prefix']).'_verify_code' : '_verify_code'; $this->expire_time = isset($param['expire_time']) ? intval($param['expire_time']) : 30; + + // 用户唯一uid + $this->user_uid = ResourcesService::UserUniqueId(); } /** @@ -146,9 +152,16 @@ class Verify */ public function CheckExpire() { - if(isset($_SESSION[$this->key_verify])) + // 空uid则存储session + if(empty($this->user_uid)) + { + $data = session($this->key_verify); + } else { + $data = cache($this->key_verify.$this->user_uid); + } + + if(!empty($data) && isset($data['time'])) { - $data = $_SESSION[$this->key_verify]; return (time() <= $data['time']+$this->expire_time); } return false; @@ -165,13 +178,20 @@ class Verify */ public function CheckCorrect($verify = '') { - if(isset($_SESSION[$this->key_verify]['verify'])) + // 空uid则存储session + if(empty($this->user_uid)) + { + $data = session($this->key_verify); + } else { + $data = cache($this->key_verify.$this->user_uid); + } + if(!empty($data) && isset($data['verify'])) { if(empty($verify) && isset($_POST['verify'])) { $verify = trim($_POST['verify']); } - return ($_SESSION[$this->key_verify]['verify'] == strtolower($verify)); + return ($data['verify'] == strtolower($verify)); } return false; } @@ -186,9 +206,12 @@ class Verify */ public function Remove() { - if(isset($_SESSION[$this->key_verify])) + // 空uid则处理session + if(empty($this->user_uid)) { - unset($_SESSION[$this->key_verify]); + session($this->key_verify, null); + } else { + cache($this->key_verify.$this->user_uid, null); } } @@ -201,10 +224,18 @@ class Verify */ private function KindofSession() { - $_SESSION[$this->key_verify] = array( - 'verify' => $this->rand_string, - 'time' => time(), - ); + $data = [ + 'verify' => $this->rand_string, + 'time' => time(), + ]; + + // 空uid则存储session + if(empty($this->user_uid)) + { + session($this->key_verify, $data); + } else { + cache($this->key_verify.$this->user_uid, $data, $this->expire_time); + } } /** diff --git a/public/static/common/lib/ueditor/dialogs/map/map.html b/public/static/common/lib/ueditor/dialogs/map/map.html index 58f416bac..8a6259b1c 100755 --- a/public/static/common/lib/ueditor/dialogs/map/map.html +++ b/public/static/common/lib/ueditor/dialogs/map/map.html @@ -4,7 +4,7 @@ - + - +