/** * @param $data * @return mixed * @throws \Nette\InvalidArgumentException */ public function changePassword($data) { $values = $this->validateInput($data, array('id', 'newPassword')); if ($user = $this->userFacade->getOne($values->id)) { $user->setPassword($this->authenticator->calculateHash($values->newPassword)); $this->userFacade->save($user); return $user; } else { throw new \Nette\InvalidArgumentException('User with ID "' . $values->id . '" does not exist'); } }
/** * @param UserPasswordForm $form */ public function formSubmitted(UserPasswordForm $form) { $values = $form->getValues(); try { $this->authenticator->authenticate(array($this->user->getModel()->getEmail(), $values->oldPassword)); $this->userManager->changePassword($values); $form->presenter->flashMessage('Password was changed.', 'success'); } catch (\Exception $ex) { $form->addError($ex->getMessage()); } }