Auth2FA/app/Model/UzivatelFacade.php

59 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Core\Funkce;
use Nette;
use Nette\Security\User;
use App\Model\Login\UserIdentity;
/**
* Třída pro manipulaci s tabulkou UZIVATEL.
*/
final class UzivatelFacade
{
public function __construct(
private Nette\Database\Explorer $database,
private User $user //DI
) {
}
/**
* Uloží TOTP secret pro dvoufázové ověření uživatele.
* Pokud je $secret null, 2FA se de facto deaktivuje.
*/
public function updateTOTPSecret(string $secret): void
{
/**
* Uživatelská identita = přihlášený user.
* @var UserIdentity
*/
$identity = $this->user->getIdentity();
$this->database->table('UZIVATEL')
->get($identity->getId())
->update([
'TOTP_SECRET' => Funkce::encrypt($secret), // šifrujeme
'IS_2FA_ENABLED' => 1
]);
}
public function disableTOTPSecret(): void
{
/**
* Uživatelská identita = přihlášený user.
* @var UserIdentity
*/
$identity = $this->user->getIdentity();
$this->database->table('UZIVATEL')
->get($identity->getId())
->update([
'TOTP_SECRET' => null,
'IS_2FA_ENABLED' => 0
]);
}
}