diff --git a/extend/catcher/CatchAuth.php b/extend/catcher/CatchAuth.php index 11cfb7e..50043ea 100644 --- a/extend/catcher/CatchAuth.php +++ b/extend/catcher/CatchAuth.php @@ -38,6 +38,12 @@ class CatchAuth return $this; } + /** + * + * @time 2020年01月07日 + * @param $condition + * @return mixed + */ public function attempt($condition) { $user = $this->authenticate($condition); @@ -53,13 +59,17 @@ class CatchAuth return $this->{$this->getDriver()}($user); } - + /** + * + * @time 2020年01月07日 + * @return mixed + */ public function user() { switch ($this->getDriver()) { case 'jwt': $model = app($this->getProvider()['model']); - return $model->where($model->getPk(), JWTAuth::auth()['id'])->find(); + return $model->where($model->getPk(), JWTAuth::auth()[$this->jwtKey()])->find(); case 'session': return Session::get($this->sessionUserKey(), null); default: @@ -67,40 +77,88 @@ class CatchAuth } } + /** + * + * @time 2020年01月07日 + * @return void + */ public function logout() { - + } + /** + * + * @time 2020年01月07日 + * @param $user + * @return string + */ protected function jwt($user) { - return JWTAuth::builder(['id' => $user->id]); + $token = JWTAuth::builder([$this->jwtKey() => $user->id]); + + JWTAuth::setToken($token); + + return $token; } - + /** + * + * @time 2020年01月07日 + * @param $user + * @return void + */ protected function session($user) { Session::set($this->sessionUserKey(), $user); } - + /** + * + * @time 2020年01月07日 + * @return string + */ protected function sessionUserKey() { return $this->guard . '_user'; } + /** + * + * @time 2020年01月07日 + * @return string + */ + protected function jwtKey() + { + return $this->guard . '_id'; + } + + /** + * + * @time 2020年01月07日 + * @return mixed + */ protected function getDriver() { return $this->auth['guards'][$this->guard]['driver']; } - + /** + * + * @time 2020年01月07日 + * @return mixed + */ protected function getProvider() { return $this->auth['providers'][$this->auth['guards'][$this->guard]['provider']]; } - + /** + * + * @time 2020年01月07日 + * @param $condition + * @return mixed + */ protected function authenticate($condition) { $provider = $this->getProvider(); diff --git a/extend/catcher/event/LoadModuleRoutes.php b/extend/catcher/event/LoadModuleRoutes.php index bcd4263..9904410 100644 --- a/extend/catcher/event/LoadModuleRoutes.php +++ b/extend/catcher/event/LoadModuleRoutes.php @@ -21,7 +21,7 @@ class LoadModuleRoutes $domain = config('catch.domain'); - $routes = $this->getRoutes(); + $routes = CatchAdmin::getRoutes(); if ($domain) { $router->domain($domain, function () use ($router, $routes) { @@ -40,16 +40,4 @@ class LoadModuleRoutes // 单独加载登录 include CatchAdmin::moduleDirectory('login') . 'route.php'; } - - /** - * - * @time 2019年12月15日 - * @return array - */ - protected function getRoutes(): array - { - $routes = CatchAdmin::getRoutes(); - - return $routes; - } }