This commit is contained in:
2022-01-13 18:41:03 +01:00
commit 0fb9f639da
159 changed files with 13183 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php declare(strict_types = 1);
namespace App\Modules\Admin\Sign;
use App\Model\App;
use App\Model\Exception\Runtime\AuthenticationException;
use App\Modules\Admin\BaseAdminPresenter;
use App\UI\Form\BaseForm;
use App\UI\Form\FormFactory;
use Nette\Application\UI\ComponentReflection;
final class SignPresenter extends BaseAdminPresenter
{
/** @var string @persistent */
public $backlink;
/** @var FormFactory @inject */
public $formFactory;
/**
* @param ComponentReflection|mixed $element
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function checkRequirements($element): void
{
}
public function actionIn(): void
{
if ($this->user->isLoggedIn()) {
$this->redirect(App::DESTINATION_AFTER_SIGN_IN);
}
}
public function actionOut(): void
{
if ($this->user->isLoggedIn()) {
$this->user->logout();
$this->flashSuccess('_front.sign.out.success');
}
$this->redirect(App::DESTINATION_AFTER_SIGN_OUT);
}
protected function createComponentLoginForm(): BaseForm
{
$form = $this->formFactory->forBackend();
$form->addEmail('email')
->setRequired(true);
$form->addPassword('password')
->setRequired(true);
$form->addCheckbox('remember')
->setDefaultValue(true);
$form->addSubmit('submit');
$form->onSuccess[] = [$this, 'processLoginForm'];
return $form;
}
public function processLoginForm(BaseForm $form): void
{
try {
$this->user->setExpiration($form->values->remember ? '14 days' : '20 minutes');
$this->user->login($form->values->email, $form->values->password);
} catch (AuthenticationException $e) {
$form->addError('Invalid username or password');
return;
}
$this->redirect(App::DESTINATION_AFTER_SIGN_IN);
}
}

View File

@@ -0,0 +1,29 @@
{block #content}
<form n:name="loginForm" class="form-signin">
<div class="text-center mb-4">
<img class="mb-4" src="https://avatars0.githubusercontent.com/u/99965?s=200&v=4" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Webapp Skeleton Admin</h1>
</div>
<div n:foreach="$form->errors as $error" class="alert alert-danger" role="alert">
{$error}
</div>
<div class="form-label-group">
<input type="email" n:name="email" class="form-control" placeholder="Email address" required autofocus>
<label n:name="email">Email address</label>
</div>
<div class="form-label-group">
<input type="password" n:name="password" class="form-control" placeholder="Password" required>
<label n:name="password">Password</label>
</div>
<div class="checkbox mb-3">
<label>
<input n:name="remember" type="checkbox"> Remember me
</label>
</div>
<button n:name="submit" class="btn btn-lg btn-primary btn-block">Sign in</button>
<p class="mt-5 mb-3 text-muted text-center">&copy; {=date('Y')}</p>
</form>