62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\Entities\UserEntity;
|
|
use App\Forms\Auth\LocalForm;
|
|
use App\Models\UserModel;
|
|
|
|
class LocalService extends AuthService
|
|
{
|
|
public function __construct(
|
|
UserModel $model,
|
|
private LocalForm $formService,
|
|
) {
|
|
parent::__construct($model);
|
|
$this->formServiceInstance = $this->formService;
|
|
// FormService에 Model 메타데이터를 설정
|
|
$this->formServiceInstance->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
]);
|
|
$this->addClassPath('Local');
|
|
}
|
|
public function getFormService(): LocalForm
|
|
{
|
|
if ($this->formServiceInstance === null) {
|
|
throw new \RuntimeException('FormService는 ' . static::class . '에서 초기화되어야 합니다.');
|
|
}
|
|
return $this->formServiceInstance;
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return ["id", "passwd",];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [];
|
|
}
|
|
public function getBatchjobButtons(): array
|
|
{
|
|
return [];
|
|
}
|
|
//기본기능
|
|
public function login(array $formDatas): UserEntity
|
|
{
|
|
$entity = $this->getEntity([
|
|
'id' => $formDatas['id'],
|
|
'status' => UserEntity::DEFAULT_STATUS
|
|
], false);
|
|
if (!$entity instanceof UserEntity) {
|
|
throw new \Exception("{$formDatas['id']}에 대한 로그인 정보를 찾을수 없습니다.");
|
|
}
|
|
if (!password_verify($formDatas['passwd'], $entity->getPassword())) {
|
|
// log_message("error", "암호: {$formDatas['passwd']}, {$entity->passwd}");
|
|
throw new \Exception("암호가 맞지 않습니다.");
|
|
}
|
|
return $this->login_process($entity);
|
|
}
|
|
}
|