/**
  * @param IUser $entity
  * @param array $roles
  */
 public function __construct(IUser $entity, $roles = array())
 {
     $this->id = $entity->getId();
     $this->entity = $entity;
     $this->roles = $roles;
     $this->loaded = TRUE;
     $this->entityClass = get_class($this->entity);
 }
 public function createComponentForm()
 {
     $form = $this->formFactory->create($this->user);
     $form->addPassword('old_password', 'Old password')->addRule(function ($input) {
         return $this->user->validatePassword($input->value);
     }, 'Password does not match with your password');
     $form->addPassword('password', 'New password')->setRequired()->addRule($form::MIN_LENGTH, 'Minimum length of the password is %d characters', 6);
     $form->addPassword('password_repeat', 'Repeat password')->setRequired()->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
     $form->addSubmit('ok', 'Change');
     $form->onAfterSuccess[] = function () {
         $this->onChange($this, $this->user);
     };
     return $form;
 }
예제 #3
0
 /**
  * @param IUser $user
  * @param string $password
  * @throws \Nette\Security\AuthenticationException
  */
 private function validatePassword(IUser $user, $password)
 {
     if (!$user->validatePassword($password)) {
         throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
 }