mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-27 13:00:23 +08:00
45 lines
756 B
PHP
45 lines
756 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Models\User as UserModel;
|
|
use App\Validators\Validator;
|
|
|
|
trait Auth
|
|
{
|
|
|
|
public function getCurrentUser()
|
|
{
|
|
$authUser = $this->getAuthUser();
|
|
|
|
if ($authUser) {
|
|
$user = UserModel::findFirst($authUser->id);
|
|
} else {
|
|
$user = new UserModel();
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
|
|
public function getLoginUser()
|
|
{
|
|
$authUser = $this->getAuthUser();
|
|
|
|
$validator = new Validator();
|
|
|
|
$validator->checkAuthUser($authUser);
|
|
|
|
$user = UserModel::findFirst($authUser->id);
|
|
|
|
return $user;
|
|
}
|
|
|
|
public function getAuthUser()
|
|
{
|
|
$auth = $this->getDI()->get('auth');
|
|
|
|
return $auth->getAuthInfo();
|
|
}
|
|
|
|
}
|