修改分享

This commit is contained in:
wuyanwen 2020-01-07 18:04:05 +08:00
parent c9b39327a5
commit b41121e35b
2 changed files with 67 additions and 21 deletions

View File

@ -38,6 +38,12 @@ class CatchAuth
return $this; return $this;
} }
/**
*
* @time 2020年01月07日
* @param $condition
* @return mixed
*/
public function attempt($condition) public function attempt($condition)
{ {
$user = $this->authenticate($condition); $user = $this->authenticate($condition);
@ -53,13 +59,17 @@ class CatchAuth
return $this->{$this->getDriver()}($user); return $this->{$this->getDriver()}($user);
} }
/**
*
* @time 2020年01月07日
* @return mixed
*/
public function user() public function user()
{ {
switch ($this->getDriver()) { switch ($this->getDriver()) {
case 'jwt': case 'jwt':
$model = app($this->getProvider()['model']); $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': case 'session':
return Session::get($this->sessionUserKey(), null); return Session::get($this->sessionUserKey(), null);
default: default:
@ -67,40 +77,88 @@ class CatchAuth
} }
} }
/**
*
* @time 2020年01月07日
* @return void
*/
public function logout() public function logout()
{ {
} }
/**
*
* @time 2020年01月07日
* @param $user
* @return string
*/
protected function jwt($user) 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) protected function session($user)
{ {
Session::set($this->sessionUserKey(), $user); Session::set($this->sessionUserKey(), $user);
} }
/**
*
* @time 2020年01月07日
* @return string
*/
protected function sessionUserKey() protected function sessionUserKey()
{ {
return $this->guard . '_user'; 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() protected function getDriver()
{ {
return $this->auth['guards'][$this->guard]['driver']; return $this->auth['guards'][$this->guard]['driver'];
} }
/**
*
* @time 2020年01月07日
* @return mixed
*/
protected function getProvider() protected function getProvider()
{ {
return $this->auth['providers'][$this->auth['guards'][$this->guard]['provider']]; return $this->auth['providers'][$this->auth['guards'][$this->guard]['provider']];
} }
/**
*
* @time 2020年01月07日
* @param $condition
* @return mixed
*/
protected function authenticate($condition) protected function authenticate($condition)
{ {
$provider = $this->getProvider(); $provider = $this->getProvider();

View File

@ -21,7 +21,7 @@ class LoadModuleRoutes
$domain = config('catch.domain'); $domain = config('catch.domain');
$routes = $this->getRoutes(); $routes = CatchAdmin::getRoutes();
if ($domain) { if ($domain) {
$router->domain($domain, function () use ($router, $routes) { $router->domain($domain, function () use ($router, $routes) {
@ -40,16 +40,4 @@ class LoadModuleRoutes
// 单独加载登录 // 单独加载登录
include CatchAdmin::moduleDirectory('login') . 'route.php'; include CatchAdmin::moduleDirectory('login') . 'route.php';
} }
/**
*
* @time 2019年12月15日
* @return array
*/
protected function getRoutes(): array
{
$routes = CatchAdmin::getRoutes();
return $routes;
}
} }