dbmsv4/app/Services/Auth/LocalService.php
2026-01-30 14:38:57 +09:00

48 lines
1.3 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
{
protected string $formClass = LocalForm::class;
public function __construct(UserModel $model)
{
parent::__construct($model);
$this->addClassPaths('Local');
}
public function createDTO(array $formDatas): LocalDTO
{
return new LocalDTO($formDatas);
}
public function getDTOClass(): string
{
return LocalDTO::class;
}
protected function getEntity_process(mixed $entity): UserEntity
{
return $entity;
}
protected function login_process(array $formDatas): UserEntity
{
$this->getActionForm()->action_init_process('login', $formDatas);
//입력값 검증
$this->getActionForm()->validate($formDatas);
//로그인 정보확인
$entity = $this->getEntity(['id' => $formDatas['id'], 'status' => 'AVAILABLE']);
if (!$entity instanceof UserEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$formDatas['id']}에 대한 로그인 정보를 찾을수 없습니다.");
}
if (!password_verify($formDatas['passwd'], $entity->getPassword())) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 암호가 맞지 않습니다.");
}
return $entity;
}
}