Beispiel #1
0
 /**
  * @return Form
  */
 protected function createComponentAddForm()
 {
     $form = $this->addUserFormFactory->create();
     $form->setTranslator($this->translator);
     $form->onSuccess[] = function (Form $form) {
         $values = $form->getValues();
         $error = FALSE;
         if ($this->usersRepository->getOneWhere(['email' => $values->email])) {
             $this->flashMessage($this->translator->translate('messages.users.mail_use'), 'danger');
             $error = TRUE;
         }
         if ($this->usersRepository->getOneWhere(['username' => $values->username])) {
             $this->flashMessage('Uživatel s tímto username již existuje.', 'danger');
             $error = TRUE;
         }
         if (!$error) {
             $this->userEntity = new UsersEntity();
             $this->userEntity->username($values->username);
             $this->userEntity->password(Passwords::hash($values->password));
             $this->userEntity->name($values->name);
             $this->userEntity->lastname($values->lastname);
             $this->userEntity->email($values->email);
             $this->userEntity->role($values->role);
             $this->usersRepository->save($this->userEntity);
             $this->flashMessage('Záznam byl vytvořen.', 'success');
             $this->redirect('default');
         }
     };
     return $form;
 }
Beispiel #2
0
 /**
  * Sign-up form factory.
  * @return Nette\Application\UI\Form
  */
 protected function createComponentSignUpForm()
 {
     $form = $this->signUpFactory->create();
     $form->onSuccess[] = function (Form $form) {
         $values = $form->getValues();
         $userByUserName = $this->usersRepository->getOneWhere(['username' => $values->username]);
         $error = 0;
         if (!is_null($userByUserName)) {
             $this->presenter->flashMessage("Uživatel s tímto username již existuje", 'error');
             $error = 1;
         }
         $userByEmail = $this->usersRepository->getOneWhere(['email' => $values->email]);
         if (!is_null($userByEmail)) {
             $this->presenter->flashMessage("Uživatel s tímto emailem již existuje", 'error');
             $error = 1;
         }
         if ($error == 0) {
             $user = new UsersEntity();
             if (trim($values->password) != '') {
                 $user->password(Passwords::hash($values->password));
             }
             $user->username($values->username);
             $user->name($values->name);
             $user->lastname($values->lastname);
             $user->email($values->email);
             $user->role($values->role);
             $this->usersRepository->save($user);
             $this->getUser()->login($values->username, $values->password);
             $this->flashMessage("Registrace proběhla v pořádku", 'success');
             $this->presenter->redirect('Homepage:default');
         }
     };
     return $form;
 }