Exemplo n.º 1
0
 /**
  * @return \Nette\Application\UI\Form
  */
 public function create()
 {
     $form = new Form();
     $form->addGroup($this->user ? 'Upravit uživatele' : 'Přidat uživatele');
     $form->addText("name", 'Jméno:')->setRequired('Vyplňte jméno');
     $form->addText("email", 'Email:')->setRequired('Vyplňte email')->addRule(function ($ctrl) {
         if ($this->user and $this->user->email == $ctrl->getValue()) {
             return TRUE;
         }
         return (bool) (!$this->userFacade->findUserByEmail($ctrl->getValue()));
     }, 'Email je obsazen, zvolte prosím jiný');
     $password = $form->addPassword("password", 'Heslo:');
     $password2 = $form->addPassword("password2", 'Heslo znovu:');
     if (!$this->user) {
         $password->setRequired('Vyplňte heslo');
         $password2->addRule(Form::FILLED, 'Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password);
     } else {
         $password2->addConditionOn($password, Form::FILLED)->setRequired('Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password);
     }
     $form->addSubmit("send", $this->user ? 'Upravit uživatele' : 'Přidat uživatele');
     $form->setRenderer(new Bs3FormRenderer());
     $form->onSuccess[] = $this->processForm;
     if ($this->user) {
         $form->setDefaults(["name" => $this->user->name, "email" => $this->user->email]);
     }
     return $form;
 }
Exemplo n.º 2
0
 /**
  * Performs an authentication.
  *
  * @param array $credentials
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $row = $this->userFacade->findUserByEmail($email);
     if (!$row) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!self::verifyPassword($password, $row->password)) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     return $row;
 }