public function formAddSubmitted(\Nette\Application\UI\Form $form) { $values = $form->values; try { $userRole = $this->em->getRepository('UserRole')->find($values->role); $values->role = $userRole; $user = new \Entity\User(); $user->setValues((array) $values); $this->em->persist($user); $token = new \Entity\PasswordRecoveryToken(); $token->setUser($user); $this->em->persist($token); $this->em->flush(); $this->mailBuilder->buildAccountCreatedEmail($user, $token)->send(); $this->flash(sprintf('User %s added', $user->name)); $this->invalidateControl('grid'); $this->popupOff(); } catch (\PDOException $e) { switch ($e->getCode()) { case '23000': $message = 'Duplicate data'; break; } $form->addError($message); $this->invalidateControl('form'); } }
public function formRecoverPasswordSubmitted(\Nette\Application\UI\Form $form) { $email = $form->values->email; $user = $this->em->getRepository('User')->findOneBy(array('email' => $email)); if ($user == null) { $form->addError(sprintf('Email %s is not registered in this system.', $email)); $this->invalidateControl('form'); } else { $token = new \Entity\PasswordRecoveryToken(); $token->setUser($user); $this->em->persist($token); $this->em->flush(); $this->hideForm = true; $this->mailBuilder->buildPasswordRecoveryEmail($user, $token)->send(); $this->flash('A message with instructions on how to reset your password has been sent to your email.'); $this->invalidateControl('form'); #send the link to email } }