Init
This commit is contained in:
26
app/modules/Admin/BaseAdminPresenter.php
Normal file
26
app/modules/Admin/BaseAdminPresenter.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Modules\Admin;
|
||||
|
||||
use App\Model\App;
|
||||
use App\Modules\Base\SecuredPresenter;
|
||||
use Nette\Application\UI\ComponentReflection;
|
||||
|
||||
abstract class BaseAdminPresenter extends SecuredPresenter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ComponentReflection|mixed $element
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
|
||||
*/
|
||||
public function checkRequirements($element): void
|
||||
{
|
||||
parent::checkRequirements($element);
|
||||
|
||||
if (!$this->user->isAllowed('Admin:Home')) {
|
||||
$this->flashError('You cannot access this with user role');
|
||||
$this->redirect(App::DESTINATION_FRONT_HOMEPAGE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
31
app/modules/Admin/Home/HomePresenter.php
Normal file
31
app/modules/Admin/Home/HomePresenter.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Modules\Admin\Home;
|
||||
|
||||
use App\Domain\Order\Event\OrderCreated;
|
||||
use App\Modules\Admin\BaseAdminPresenter;
|
||||
use Nette\Application\UI\Form;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class HomePresenter extends BaseAdminPresenter
|
||||
{
|
||||
|
||||
/** @var EventDispatcherInterface @inject */
|
||||
public $dispatcher;
|
||||
|
||||
protected function createComponentOrderForm(): Form
|
||||
{
|
||||
$form = new Form();
|
||||
|
||||
$form->addText('order', 'Order name')
|
||||
->setRequired(true);
|
||||
$form->addSubmit('send', 'OK');
|
||||
|
||||
$form->onSuccess[] = function (Form $form): void {
|
||||
$this->dispatcher->dispatch(new OrderCreated($form->values->order), OrderCreated::NAME);
|
||||
};
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
8
app/modules/Admin/Home/templates/default.latte
Normal file
8
app/modules/Admin/Home/templates/default.latte
Normal file
@@ -0,0 +1,8 @@
|
||||
{block #content}
|
||||
<h1>SECRET PAGE!</h1>
|
||||
<a n:href="Sign:out" class="btn btn-danger">Logout</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2>Orders</h2>
|
||||
{control orderForm}
|
||||
75
app/modules/Admin/Sign/SignPresenter.php
Normal file
75
app/modules/Admin/Sign/SignPresenter.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
29
app/modules/Admin/Sign/templates/in.latte
Normal file
29
app/modules/Admin/Sign/templates/in.latte
Normal 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">© {=date('Y')}</p>
|
||||
</form>
|
||||
7
app/modules/Admin/templates/@layout.latte
Normal file
7
app/modules/Admin/templates/@layout.latte
Normal file
@@ -0,0 +1,7 @@
|
||||
{layout '../../Base/templates/@layout.latte'}
|
||||
|
||||
{block #head}
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" defer />
|
||||
<link rel="stylesheet" href="{$basePath}/assets/admin.css" defer />
|
||||
<script src="{$basePath}/assets/admin.js" defer></script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user