1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00
2024-05-02 11:04:21 +08:00

61 lines
1.2 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Http\Admin\Services;
use App\Services\Auth\Admin as AdminAuth;
use App\Services\Auth\Home as HomeAuth;
use App\Validators\Account as AccountValidator;
class Session extends Service
{
/**
* @var AdminAuth
*/
protected $auth;
public function __construct()
{
$this->auth = $this->getDI()->get('auth');
}
public function login()
{
$post = $this->request->getPost();
$validator = new AccountValidator();
$user = $validator->checkAdminLogin($post['account'], $post['password']);
$validator->checkIfAllowLogin($user);
$this->auth->saveAuthInfo($user);
$this->loginHome($user);
$this->eventsManager->fire('Account:afterLogin', $this, $user);
}
public function logout()
{
$user = $this->getLoginUser();
$this->auth->clearAuthInfo();
$this->eventsManager->fire('Account:afterLogout', $this, $user);
}
protected function loginHome($user)
{
$auth = new HomeAuth();
$auth->saveAuthInfo($user);
}
}