<?php

namespace App\Libraries\Adapter\Auth;

use App\Entities\UserEntity;

class LocalAuth extends Auth
{
	public function __construct(string $site,  $debug = false)
	{
		parent::__construct($site, $debug);
	}

	public function getAuthButton()
	{
		return "";
	}

	protected function execute_process(): UserEntity
	{
		$formDatas = $this->getFormDatas();
		if (!isset($formDatas['id']) || !$formDatas['id'] || !isset($formDatas['passwd']) || !$formDatas['passwd']) {
			throw new \Exception("ID 나 암호의 값이 없습니다.");
		}
		$entity = $this->getUserModel()->getEntity(['id' => $formDatas['id'], 'status' => DEFAULTS['STATUS']]);
		if (!password_verify($formDatas['passwd'], $entity->passwd)) {
			throw new \Exception("암호가 맞지않습니다.");
		}
		//Session에 인증정보 설정
		return $this->setSession_process($entity);;
	}
}
