/**
  * @Route("/{_locale}/auth/forgot", name="auth_forgot")
  * @Template()
  */
 public function forgotAction()
 {
     $form = $this->createFormBuilder()->add('username', 'text', array('label' => 'Username or email'))->getForm();
     if ($this->getRequest()->getMethod() == 'POST') {
         $form->bind($this->getRequest());
         $post = $form->getData();
         $em = $this->getDoctrine()->getManager();
         $user = $em->getRepository('ClubUserBundle:User')->findOneBy(array('member_number' => $post['username']));
         if (!$user instanceof \Club\UserBundle\Entity\User) {
             $email = $em->getRepository('ClubUserBundle:ProfileEmail')->findOneBy(array('email_address' => $post['username']));
             if ($email instanceof \Club\UserBundle\Entity\ProfileEmail) {
                 $user = $email->getProfile()->getUser();
             }
         }
         if ($user instanceof \Club\UserBundle\Entity\User) {
             $forgot = new \Club\UserBundle\Entity\ForgotPassword();
             $forgot->setUser($user);
             $em->persist($forgot);
             $em->flush();
             $event = new \Club\UserBundle\Event\FilterForgotPasswordEvent($forgot);
             $this->get('event_dispatcher')->dispatch(\Club\UserBundle\Event\Events::onPasswordReset, $event);
         }
         $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('You will receive an email within a few minutes.'));
         return $this->redirect($this->generateUrl('homepage'));
     }
     return array('form' => $form->createView());
 }
Beispiel #2
0
 /**
  * @Route("/auth/forgot", name="auth_forgot")
  * @Template()
  */
 public function forgotAction()
 {
     $form = $this->createForm(new \Club\UserBundle\Form\RequestPassword());
     if ($this->getRequest()->getMethod() == 'POST') {
         $form->bindRequest($this->getRequest());
         $post = $form->getData();
         $em = $this->getDoctrine()->getEntityManager();
         $user = $em->getRepository('ClubUserBundle:User')->findOneBy(array('member_number' => $post['username']));
         if (!$user instanceof \Club\UserBundle\Entity\User) {
             $email = $em->getRepository('ClubUserBundle:ProfileEmail')->findOneBy(array('email_address' => $post['email']));
             if ($email instanceof \Club\UserBundle\Entity\ProfileEmail) {
                 $user = $email->getProfile()->getUser();
             }
         }
         if ($user instanceof \Club\UserBundle\Entity\User) {
             $forgot = new \Club\UserBundle\Entity\ForgotPassword();
             $forgot->setUser($user);
             $em->persist($forgot);
             $em->flush();
             $event = new \Club\UserBundle\Event\FilterForgotPasswordEvent($forgot);
             $this->get('event_dispatcher')->dispatch(\Club\UserBundle\Event\Events::onPasswordReset, $event);
         }
         return $this->redirect($this->generateUrl('login'));
     }
     return array('form' => $form->createView());
 }