dbms/app/Services/Auth/LocalService.php
2025-05-12 16:58:29 +09:00

56 lines
1.2 KiB
PHP

<?php
namespace App\Services\Auth;
use App\Entities\UserEntity;
use App\Models\UserModel;
use CodeIgniter\HTTP\IncomingRequest;
class LocalService extends AuthService
{
public function __construct(?IncomingRequest $request = null)
{
parent::__construct($request);
}
final public function getClassName(): string
{
return parent::getClassName() . DIRECTORY_SEPARATOR . "Local";
}
final public function getModelClass(): UserModel
{
return new UserModel();
}
final public function getEntityClass(): UserEntity
{
return new UserEntity();
}
public function getFields(): array
{
return ['id', 'passwd'];
}
public function getFilterFields(): array
{
return [];
}
public function getBatchJobFields(): array
{
return [];
}
public function checkUser(array $formDatas): UserEntity
{
$entity = $this->getEntity(['id' => $formDatas['id']]);
if (is_null($entity) || !isset($entity->passwd)) {
throw new \Exception("사용자ID: {$formDatas['id']}가 존재하지 않습니다.");
}
if (!password_verify($formDatas['passwd'], $entity->passwd)) {
// log_message("error", "암호: {$formDatas['passwd']}, {$entity->passwd}");
throw new \Exception("암호가 맞지 않습니다.");
}
return $entity;
}
}