mirror of
https://github.com/netcccyun/dnsmgr.git
synced 2024-11-16 03:32:28 +08:00
53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\middleware;
|
|
|
|
use think\facade\Db;
|
|
|
|
class AuthUser
|
|
{
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
$islogin = false;
|
|
$cookie = cookie('user_token');
|
|
$user = null;
|
|
if($cookie){
|
|
$token=authcode($cookie, 'DECODE', env('app.sys_key'));
|
|
if($token){
|
|
list($type, $uid, $sid, $expiretime) = explode("\t", $token);
|
|
if($type == 'user'){
|
|
$user = Db::name('user')->where('id', $uid)->find();
|
|
if($user && $user['status']==1){
|
|
$session=md5($user['id'].$user['password']);
|
|
if($session==$sid && $expiretime>time()) {
|
|
$islogin = true;
|
|
}
|
|
$user['type'] = 'user';
|
|
$user['permission'] = [];
|
|
if($user['level'] == 1){
|
|
$user['permission'] = Db::name('permission')->where('uid', $uid)->column('domain');
|
|
}
|
|
}
|
|
}elseif($type == 'domain'){
|
|
$user = Db::name('domain')->where('id', $uid)->find();
|
|
if($user && $user['is_sso']==1){
|
|
$session=md5($user['id'].$user['name']);
|
|
if($session==$sid && $expiretime>time()) {
|
|
$islogin = true;
|
|
}
|
|
$user['username'] = $user['name'];
|
|
$user['regtime'] = $user['addtime'];
|
|
$user['type'] = 'domain';
|
|
$user['level'] = 0;
|
|
$user['permission'] = [$user['name']];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$request->islogin = $islogin;
|
|
$request->user = $user;
|
|
return $next($request);
|
|
}
|
|
}
|