ACC SHELL
<?php
use Nette\Application\UI,
Nette\Security as NS,
Nette\Environment;
/**
* Sign in/out presenters.
*/
class PrihlasitPresenter extends BasePresenter
{
/**
* Sign in form component factory.
* @return Nette\Application\UI\Form
*/
protected function createComponentSignInForm()
{
$form = new UI\Form;
$form->addText('email', 'Email', 30)
->addRule(Nette\Application\UI\Form::EMAIL, 'Zadej platný email!')
->setRequired('Prosím vyplňte přihlašovací jméno.');
$form->addPassword('heslo', 'Heslo:')
->setRequired('Prosím vyplňte heslo.');
$form->addCheckbox('remember', 'Zapamatuj si mě');
$form->addHidden('url', @$this->request->parameters['url']);
$form->addSubmit('send', 'Přihlásit');
$form->onSuccess[] = $this->signInFormSubmitted;
return $form;
}
public function signInFormSubmitted($form)
{
try {
$values = $form->getValues();
if ($values->remember) {
$this->getUser()->setExpiration('+ 999 days', FALSE);
} else {
$this->getUser()->setExpiration('+ 999 days', TRUE);
}
$this->getUser()->login($values->email, $values->heslo);
$this->flashMessage('Vítej, ' . $this->getUser()->getIdentity()->prezdivka . '!', 'success');
if (strlen($values->url) > 0)
{
$presenter = substr($values->url, strpos($values->url, '=') + 1);
$action = substr($presenter, strpos($presenter, '=') + 1);
$id = substr($action, strpos($action, '=') + 1) ?: '';
$params = '?' . substr($id, strpos($id, '&') + 1);
$presenter = substr($presenter, 0, strpos($presenter, '&'));
$action = substr($action, 0, strpos($action, '&'));
if (strpos($id, '&') !== false)
{
$id = substr($id, 0, strpos($id, '&')) ?: '';
}
Environment::getHttpResponse()->redirect('../' . $presenter . '/' . $action . '/' . $id . $params);
}
else
{
$this->redirect('Homepage:');
}
} catch (NS\AuthenticationException $e) {
$this->template->unsuccessfulLogin = true;
$form->addError($e->getMessage());
}
}
public function actionZrusit()
{
$this->getUser()->logout();
$this->flashMessage('Fotbalu zdar!');
$this->redirect('Homepage:');
}
}
ACC SHELL 2018