Commit f17a5442 authored by Roman Ondráček's avatar Roman Ondráček

Core: fix bug at sign in page (fix #226)

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent b65e1c6b
Pipeline #2318 canceled with stages
......@@ -102,7 +102,7 @@ class ComponentPresenter extends ProtectedPresenter {
* @throws JsonException
*/
public function actionDelete(int $id): void {
if ($this->user->isInRole('power')) {
if ($this->getUser()->isInRole('power')) {
try {
$this->configManager->delete($id);
$this->flashSuccess('config.messages.successes.delete');
......
......@@ -23,7 +23,6 @@ namespace App\CoreModule\Forms;
use App\CoreModule\Presenters\SignPresenter;
use Nette\Application\UI\Form;
use Nette\Security\AuthenticationException;
use Nette\Security\User;
use Nette\SmartObject;
/**
......@@ -43,19 +42,12 @@ class SignInFormFactory {
*/
private $presenter;
/**
* @var User User object
*/
private $user;
/**
* Constructor
* @param FormFactory $factory Generic form factory
* @param User $user User object
*/
public function __construct(FormFactory $factory, User $user) {
public function __construct(FormFactory $factory) {
$this->factory = $factory;
$this->user = $user;
}
/**
......@@ -83,8 +75,9 @@ class SignInFormFactory {
public function signIn(Form $form): void {
$values = $form->getValues();
try {
$this->user->setExpiration($values->remember === true ? '14 days' : '20 minutes');
$this->user->login($values->username, $values->password);
$user = $this->presenter->getUser();
$user->setExpiration($values->remember === true ? '14 days' : '30 minutes');
$user->login($values->username, $values->password);
$this->presenter->flashSuccess('core.sign.inForm.messages.success');
if ($this->presenter->backlink === null) {
$this->presenter->redirect('Homepage:default');
......
......@@ -107,8 +107,9 @@ class UserEditFormFactory {
*/
public function save(Form $form): void {
$values = $form->getValues();
$user = $this->presenter->getUser();
try {
if ($this->presenter->user->id === $this->id &&
if ($user->getId() === $this->id &&
$values->oldPassword !== '' &&
$values->newPassword !== '') {
$this->userManager->changePassword($this->id, $values->oldPassword, $values->newPassword);
......@@ -116,8 +117,8 @@ class UserEditFormFactory {
$role = $values->role ?? null;
$language = $values->language ?? null;
$this->userManager->edit($this->id, $values->username, $role, $language);
if ($this->presenter->user->id === $this->id) {
$this->presenter->user->logout();
if ($user->getId() === $this->id) {
$user->logout();
}
$message = $form->getTranslator()->translate('messages.successEdit', ['username' => $values->username]);
$this->presenter->flashSuccess($message);
......
......@@ -61,8 +61,8 @@ abstract class ProtectedPresenter extends BasePresenter {
* @param mixed $element Element
*/
public function checkRequirements($element): void {
if (!$this->user->isLoggedIn()) {
if ($this->user->getLogoutReason() === IUserStorage::INACTIVITY) {
if (!$this->getUser()->isLoggedIn()) {
if ($this->getUser()->getLogoutReason() === IUserStorage::INACTIVITY) {
$this->flashInfo('core.signOut.inactivity');
}
$this->redirect(':Core:Sign:In', ['backlink' => $this->storeRequest()]);
......
......@@ -53,7 +53,7 @@ class SignPresenter extends BasePresenter {
* Signs user in
*/
public function actionIn(): void {
if ($this->user->isLoggedIn()) {
if ($this->getUser()->isLoggedIn()) {
$this->redirect('Homepage:');
}
}
......@@ -62,13 +62,11 @@ class SignPresenter extends BasePresenter {
* Signs user out
*/
public function actionOut(): void {
if (!$this->user->isLoggedIn()) {
$this->redirect('Sign:in');
} else {
if ($this->getUser()->isLoggedIn()) {
$this->getUser()->logout();
$this->flashSuccess('core.signOut.message');
$this->redirect('Sign:in');
}
$this->redirect('Sign:in');
}
/**
......
......@@ -84,8 +84,8 @@ class UserPresenter extends ProtectedPresenter {
public function actionDelete(int $id): void {
$user = $this->userManager->getInfo($id);
$this->userManager->delete($id);
if ($this->user->id === $id) {
$this->user->logout(true);
if ($this->getUser()->getId() === $id) {
$this->getUser()->logout(true);
}
$message = $this->translator->translate('core.user.form.messages.successDelete', ['username' => $user['username']]);
$this->flashSuccess($message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment