1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 11:58:41 +08:00
2020-05-24 20:49:55 +08:00

89 lines
2.0 KiB
PHP

<?php
namespace App\Http\Web\Services;
use App\Repos\User as UserRepo;
use App\Services\Auth as AuthService;
use App\Services\Frontend\Account\Register as RegisterService;
use App\Services\Frontend\Account\RegisterByEmail as RegisterByEmailService;
use App\Services\Frontend\Account\RegisterByPhone as RegisterByPhoneService;
use App\Validators\Account as AccountValidator;
use App\Validators\Captcha as CaptchaValidator;
class Account extends Service
{
/**
* @var AuthService
*/
protected $auth;
public function __construct()
{
$this->auth = $this->getDI()->get('auth');
}
public function register()
{
$service = new RegisterService();
$account = $service->handle();
$userRepo = new UserRepo();
$user = $userRepo->findById($account->id);
$this->auth->saveAuthInfo($user);
}
public function registerByEmail()
{
$service = new RegisterByEmailService();
$user = $service->handle();
$this->auth->saveAuthInfo($user);
}
public function registerByPhone()
{
$service = new RegisterByPhoneService();
$user = $service->handle();
$this->auth->saveAuthInfo($user);
}
public function loginByPassword()
{
$post = $this->request->getPost();
$captchaValidator = new CaptchaValidator();
$captchaValidator->checkCode($post['ticket'], $post['rand']);
$accountValidator = new AccountValidator();
$user = $accountValidator->checkUserLogin($post['account'], $post['password']);
$this->auth->saveAuthInfo($user);
}
public function loginByVerify()
{
$post = $this->request->getPost();
$accountValidator = new AccountValidator();
$user = $accountValidator->checkVerifyLogin($post['account'], $post['verify_code']);
$this->auth->saveAuthInfo($user);
}
public function logout()
{
$this->auth->clearAuthInfo();
}
}