Login cookie
This commit is contained in:
parent
864f5a68fe
commit
3aeb7fd314
@ -5,6 +5,7 @@ use think\Model;
|
|||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\Session;
|
use think\facade\Session;
|
||||||
|
use think\facade\Cookie;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
use taoler\com\Api;
|
use taoler\com\Api;
|
||||||
|
|
||||||
@ -54,6 +55,11 @@ class User extends Model
|
|||||||
//将用户数据写入Session
|
//将用户数据写入Session
|
||||||
Session::set('user_id',$user['id']);
|
Session::set('user_id',$user['id']);
|
||||||
Session::set('user_name',$user['name']);
|
Session::set('user_name',$user['name']);
|
||||||
|
if(!empty($data['remember'])){
|
||||||
|
Cookie::set('user_id', $user['id'], 604800);
|
||||||
|
Cookie::set('user_name', $user['name'], 604800);
|
||||||
|
}
|
||||||
|
|
||||||
$ip = request()->ip();
|
$ip = request()->ip();
|
||||||
/*
|
/*
|
||||||
$url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN';
|
$url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN';
|
||||||
|
@ -8,6 +8,7 @@ use think\facade\Db;
|
|||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use think\facade\Session;
|
use think\facade\Session;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
|
use think\facade\Cookie;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use app\common\model\Article;
|
use app\common\model\Article;
|
||||||
use app\common\model\Collection;
|
use app\common\model\Collection;
|
||||||
@ -199,6 +200,8 @@ class User extends BaseController
|
|||||||
public function logout()
|
public function logout()
|
||||||
{
|
{
|
||||||
Session::clear();
|
Session::clear();
|
||||||
|
Cookie::delete('user_name');
|
||||||
|
Cookie::delete('user_id');
|
||||||
if(Session::has('user_id')){
|
if(Session::has('user_id')){
|
||||||
return json(['code' => -1, 'msg' => '退出失败']);
|
return json(['code' => -1, 'msg' => '退出失败']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
\app\middleware\LoginCookie::class,
|
||||||
\app\middleware\Install::class,
|
\app\middleware\Install::class,
|
||||||
\app\middleware\Browse::class,
|
\app\middleware\Browse::class,
|
||||||
//app\middleware\LoginCheck::class,
|
//app\middleware\LoginCheck::class,
|
||||||
|
18
app/middleware/LoginCookie.php
Normal file
18
app/middleware/LoginCookie.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\middleware;
|
||||||
|
use think\facade\Session;
|
||||||
|
use think\facade\Cookie;
|
||||||
|
|
||||||
|
class LoginCookie
|
||||||
|
{
|
||||||
|
public function handle($request, \Closure $next)
|
||||||
|
{
|
||||||
|
//登陆前Cookie检测
|
||||||
|
if(Cookie::get('user_id')){
|
||||||
|
//dump(Cookie::get('user_id'));
|
||||||
|
Session::set('user_id',Cookie::get('user_id'));
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,10 @@
|
|||||||
<div >
|
<div >
|
||||||
<img src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?'+Math.random();" style="float:left; cursor:pointer;" id="captcha" alt="captcha" />
|
<img src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?'+Math.random();" style="float:left; cursor:pointer;" id="captcha" alt="captcha" />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<input type="checkbox" name="remember" title="记住密码" lay-skin="primary" lay-filter="remember" value="1" checked>
|
||||||
|
<a href="{:url('login/forget')}">忘记密码?</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<button type="submit" name="submit" class="layui-btn" lay-filter="user" lay-submit id="login">立即登录</button>
|
<button type="submit" name="submit" class="layui-btn" lay-filter="user" lay-submit id="login">立即登录</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user