1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 20:00:27 +08:00
xiaochong0302 c0e38d68fd 精简auth
2020-04-07 19:32:00 +08:00

63 lines
1.1 KiB
PHP

<?php
namespace App\Services\Frontend;
use App\Models\User as UserModel;
use App\Repos\User as UserRepo;
use App\Services\Auth as AuthService;
use App\Validators\Validator as AppValidator;
use Phalcon\Mvc\User\Component;
class Service extends Component
{
public function getCurrentUser()
{
$authUser = $this->getAuthUser();
if (!$authUser) {
return $this->getGuestUser();
}
$userRepo = new UserRepo();
return $userRepo->findById($authUser['id']);
}
public function getLoginUser()
{
$authUser = $this->getAuthUser();
$validator = new AppValidator();
$validator->checkAuthUser($authUser);
dd($authUser);
$userRepo = new UserRepo();
return $userRepo->findById($authUser['id']);
}
public function getAuthUser()
{
/**
* @var AuthService $auth
*/
$auth = $this->getDI()->get('auth');
return $auth->getAuthInfo();
}
public function getGuestUser()
{
$user = new UserModel();
$user->id = 0;
$user->name = 'guest';
return $user;
}
}