| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Http\Middleware\Manager;
- use App\Facades\Servers\Encrypts\AccessToken;
- use Closure;
- use Illuminate\Http\Request;
- class Login
- {
- // 无需验证的路径
- protected $except = [
- 'manager/login/index',
- 'manager/login/mobile',
- 'manager/citys/list'
- ];
- //默认配置
- protected $_config = [
- 'auth_on' => true, // 认证开关
- 'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。
- 'auth_group' => 'auth_group', // 用户组数据表名
- 'auth_group_access' => 'auth_group_access', // 用户-用户组关系表
- 'auth_rule' => 'auth_rule' // 权限规则表
- ];
- /**
- * $prefix表前缀
- */
- public function __construct()
- {
- // 判断配置
- if (config('AUTH_CONFIG')) {
- //可设置配置项 AUTH_CONFIG, 此配置项为数组。
- $this->_config = array_merge($this->_config, config('AUTH_CONFIG'));
- }
- }
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle(Request $request, Closure $next)
- {
- // 当前路径
- $path = ltrim($request->getPathInfo(), '/');
- // 判断是否需要验证登录
- if (!in_array($path, $this->except)) {
- // 获取登录结果
- $token = (string) $request->input('access_token_manager', '');
- // 解码
- $userInfo = AccessToken::decode($token);
- // 判断登录时效
- if (isset($userInfo['error'])) return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => $userInfo['error']]);
- if ($userInfo['type'] != 'manager') return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => '登录失效']);
- if ($userInfo['expire'] < time()) return json_send(['code' => 'no_login', 'msg' => '登录失效,请您重新登录', 'data' => '登录失效']);
- // 获取就得令牌
- // $oldToken = (new AdminUser())->getLogin($userInfo['uid'],'manager');
- // 比对令牌
- // if( $oldToken != md5($token) ) return json_send(['code'=>'no_login','msg'=>'登录失效,请重新登录']);
- // 是否是超管
- $userInfo['is_super'] = is_super($userInfo['uid'], 'manager') ? 1 : 0;
- // 追加入
- $request['access_token'] = $userInfo;
- }
- // 返回下一个闭包
- return $next($request);
- }
- }
|