public function processUserRegistration(Form $form)
 {
     $values = $form->getValues();
     $forbiddenNames = array_flip(['systém', 'system', 'admin', 'administrator', 'administrátor']);
     if (array_key_exists(strtolower($values['username']), $forbiddenNames)) {
         $form->addError('Vámi zadané jméno nelze použít. Vyberte si prosím jiné.');
         return;
     }
     $values['ip'] = $this->getHttpRequest()->getRemoteAddress();
     $values['role'] = 'employee';
     $user = new User($values['username'], $values['password'], $values['email'], $values['ip'], $this->invitation->getSender(), $values['role']);
     try {
         $this->usersFacade->registerNewUser($user, $this->invitation);
         $this->flashMessage('Váš účet byl vytvořen. Nyní se můžete přihlásit.', 'success');
         $this->redirect('Login:default');
     } catch (InvitationValidityException $iu) {
         $this->flashMessage('Registrovat se může pouze uživatel s platnou pozvánkou.', 'warning');
         $this->redirect('Login:default');
     } catch (InvalidUserInvitationEmailException $iue) {
         $form->addError('Nesouhlasí Vámi zadaný E-mail a E-mail vázaný na pozvánku.');
     } catch (\Exceptions\Runtime\DuplicateUsernameException $du) {
         $form->addError('Vámi zvolené jméno využívá již někdo jiný. Vyberte si prosím jiné jméno.');
     } catch (\Exceptions\Runtime\DuplicateEmailException $de) {
         $this->flashMessage('E-mail svázaný s pozvánkou využívá již jeden z registrovaných
              uživatelů. Nechte si zaslat novou pozvánku s jinou E-mailovou adresou.', 'warning');
         $this->redirect('Login:default');
     } catch (DBALException $d) {
         $form->addError('Registraci nelze dokončit. Zkuste to prosím později.');
     }
 }
 private function loadUsers()
 {
     if (empty($this->possibleRecipients)) {
         $this->restrictedUsers = $this->usersFacade->findRestrictedUsers($this->user);
         $this->users = $this->usersFacade->findAllUsers();
         $this->possibleRecipients = array_merge($this->users, $this->restrictedUsers);
     }
 }
 public function processChangePassword(Form $form, $values)
 {
     $this->onBeforeChange($form, $this->user);
     try {
         $this->user->password = $values['password'];
         $this->usersFacade->saveUser($this->user);
     } catch (\Exception $e) {
         $this->onError($form, $this->user);
     }
     $this->onSuccess($form, $this->user);
 }
 public function __construct(ListingResult $listingResult, RecipientsSelectBoxFactory $recipientsSelectBoxFactory, SharedListingNotification $sharedListingNotification, IItemsTableControlFactory $itemsTableControlFactory, ListingsFacade $listingFacade, UsersFacade $usersFacade)
 {
     $this->listingResult = $listingResult;
     $this->listing = $listingResult->getListing();
     $this->user = $listingResult->getListing()->getUser();
     $this->recipientsSelectBoxFactory = $recipientsSelectBoxFactory;
     $this->sharedListingNotification = $sharedListingNotification;
     $this->itemsTableControlFactory = $itemsTableControlFactory;
     $this->listingFacade = $listingFacade;
     $this->usersFacade = $usersFacade;
     $this->restrictedUsers = $this->usersFacade->findRestrictedUsers($this->user);
     $this->users = $this->usersFacade->findAllUsers();
 }
 public function processSaveWholeName(Form $form, $values)
 {
     $user = $this->user->getIdentity();
     $user->name = $values['name'];
     try {
         $this->usersFacade->saveUser($user);
         $this->flashMessage('Vaše jméno bylo úspěšně změněno.', 'success');
         $this->redirect('this');
     } catch (\Exception $e) {
         $this->flashMessage('Jméno nemohlo být změněno. Zkuste akci opakovat později.', 'error');
         return;
     }
 }
 public function actionChange($email, $token)
 {
     $this->userEntity = $this->usersFacade->getUserByEmail($email);
     if ($this->userEntity === null or $this->userEntity->token === null or $this->userEntity->token !== $token) {
         $this->flashMessage('Nelze změnit heslo účtu spojeného s E-mailem ' . $email, 'warning');
         $this->redirect('Password:reset');
     }
     $currentTime = new \DateTime();
     if ($currentTime > $this->userEntity->tokenValidity) {
         $this->flashMessage('Čas na změnu hesla vypršel. Pro obnovu hesla využijte formuláře níže.', 'warning');
         $this->redirect('Password:reset');
     }
     $this['passwordChangeForm']['username']->setDefaultValue($this->userEntity->username);
     $this['passwordChangeForm']['email']->setDefaultValue($this->userEntity->email);
 }
 private function toggleAccountAccessibility($id)
 {
     try {
         $this->checkPermission($id);
         $user = $this->getUser($id);
         if ($user !== null) {
             $user->toggleAccessibility();
             $this->usersFacade->saveUser($user);
         } else {
             $this->redirect('this');
         }
         return $user;
     } catch (\Exception $e) {
         $this->flashMessage('Nastala uzavírání/otevírání účtu nastala chyba.', 'error');
         $this->redirect('this');
     }
 }
 public function render()
 {
     $template = $this->getTemplate();
     $template->setFile(__DIR__ . '/template.latte');
     $paginator = $this['paginator']->getPaginator();
     if (empty($this->users)) {
         $usersResultSet = $this->usersFacade->fetchUsers($this->usersQuery);
         $usersResultSet->applyPaginator($paginator, 15);
         $this->users = Arrays::associate($usersResultSet->toArray(AbstractQuery::HYDRATE_ARRAY), 'id');
         unset($this->users[$this->userEntity->getId()]);
     }
     $template->users = $this->users;
     if (empty($this->alreadyBlockedUsers)) {
         $alreadyBlockedUsers = Arrays::associate($this->usersFacade->fetchUsers((new UsersOverviewQuery())->onlyWithFields(['id'])->findUsersBlockedBy($this->userEntity))->toArray(AbstractQuery::HYDRATE_ARRAY), 'id');
         $this->alreadyBlockedUsers = $alreadyBlockedUsers;
     }
     if ($this->userEntity->isInRole('admin') and empty($this->usersWithClosedAccount)) {
         $uwca = Arrays::associate($this->usersFacade->fetchUsers((new UsersOverviewQuery())->onlyWithFields(['id'])->findUsersWithClosedAccount())->toArray(AbstractQuery::HYDRATE_ARRAY), 'id');
         $this->usersWithClosedAccount = $uwca;
     }
     $template->areRelationshipsRestrictionsVisible = $this->areRelationshipsRestrictionsVisible;
     $template->isHintBoxVisible = $this->isHintBoxVisible;
     $template->render();
 }