/**
  * Formulář pro změnu zapomenutého hesla
  * @return Form
  */
 protected function createComponentChangeForgottenPasswordForm()
 {
     $form = new Form();
     $form->setTranslator($this->getTranslator());
     $form->addHidden('user');
     $form->addHidden('code');
     $form->addHidden('id');
     $form->addText('email', 'E-mail:')->setAttribute('readonly')->setDisabled(true);
     $newPassword = $form->addPassword('newPassword', 'New password:'******'minimum password length is %d characters', 5)->setRequired('Input new password!');
     $form->addPassword('newPassword2', 'New password:'******'Input new password!')->addRule(Form::EQUAL, 'New passwords do not match!', $newPassword);
     $form->addSubmit('save', 'Change password')->onClick[] = function (SubmitButton $button) {
         //změna hesla
         $values = $button->getForm(true)->getValues();
         try {
             $user = $this->usersFacade->findUser($values->user);
             $userForgottenPassword = $this->usersFacade->findUserForgottenPassword($values->id);
             if ($userForgottenPassword->user->userId != $user->userId || $userForgottenPassword->code != $values->code) {
                 throw new \Exception('Hacking attempt!');
             }
         } catch (\Exception $e) {
             $this->flashMessage('Requested password renewal not found! Maybe, the renewal code was too old. Please go to "Forgotten password".', 'error');
             $this->redirect('login');
             return;
         }
         $user->password = Passwords::hash($values->newPassword);
         if ($this->usersFacade->saveUser($user)) {
             $this->flashMessage('New password saved...');
         }
         //finální přesměrování
         $this->redirect('login');
     };
     $form->addSubmit('storno', 'storno')->setValidationScope([])->onClick[] = function (SubmitButton $button) {
         $values = $button->getForm(true)->getValues();
         $redirectParams = [];
         if ($this->user->id != $values->user) {
             $redirectParams['user'] = $values->user;
         }
         $this->redirect('details', $redirectParams);
     };
     return $form;
 }