53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\DTOs\Auth\LocalDTO;
|
|
use App\Entities\UserEntity;
|
|
use App\Forms\Auth\LocalForm;
|
|
use App\Models\UserModel;
|
|
use RuntimeException;
|
|
|
|
class LocalService extends AuthService
|
|
{
|
|
public function __construct(UserModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Local');
|
|
}
|
|
|
|
public function getFormService(): LocalForm
|
|
{
|
|
if ($this->formServiceInstance === null) {
|
|
$this->formServiceInstance = new LocalForm();
|
|
$this->formServiceInstance->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false),
|
|
]);
|
|
}
|
|
return $this->formServiceInstance;
|
|
}
|
|
protected function login_process(array $formDatas): UserEntity
|
|
{
|
|
$entity = $this->getEntity(['id' => $formDatas['id'], 'status' => 'AVAILABLE'], true);
|
|
if (!$entity instanceof UserEntity) {
|
|
throw new \Exception("{$formDatas['id']}에 대한 로그인 정보를 찾을수 없습니다.");
|
|
}
|
|
if (!password_verify($formDatas['passwd'], $entity->getPassword())) {
|
|
throw new \Exception("암호가 맞지 않습니다.");
|
|
}
|
|
return $entity;
|
|
}
|
|
|
|
public function login(object $dto): UserEntity
|
|
{
|
|
if (!$dto instanceof LocalDTO) {
|
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다.");
|
|
}
|
|
return parent::login($dto);
|
|
}
|
|
}
|