public function sendEmailAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $data = array();
         $response = new \Symfony\Component\HttpFoundation\JsonResponse();
         $username = $request->request->get('username');
         /** @var $user UserInterface */
         $user = $this->container->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);
         if (null === $user) {
             $data['message'] = $this->trans('resetting.request.invalid_username', array('%username%' => $username));
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
             $data['message'] = $this->trans('resetting.password_already_requested', array());
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if (null === $user->getConfirmationToken()) {
             /** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
             $tokenGenerator = $this->container->get('fos_user.util.token_generator');
             $user->setConfirmationToken($tokenGenerator->generateToken());
         }
         $this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
         $user->setPasswordRequestedAt(new \DateTime());
         $this->container->get('fos_user.user_manager')->updateUser($user);
         $data['message'] = $this->trans('resetting.check_email', array('%email%' => $username));
         $response->setData($data);
         return $response;
     } else {
         return parent::sendEmailAction($request);
     }
 }
 public function sendEmailAction()
 {
     /** @var Request $request */
     $request = Request::createFromGlobals();
     if ($request->isXmlHttpRequest()) {
         $username = $request->request->get('username');
         /** @var $user UserInterface */
         $user = $this->container->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);
         if (null === $user) {
             return $this->container->get('templating')->renderResponse('FOSUserBundle:Resetting:request.html.' . $this->getEngine(), array('invalid_username' => $username));
         }
         if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
             return $this->container->get('templating')->renderResponse('FOSUserBundle:Resetting:passwordAlreadyRequested.html.' . $this->getEngine());
         }
         if (null === $user->getConfirmationToken()) {
             /** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
             $tokenGenerator = $this->container->get('fos_user.util.token_generator');
             $user->setConfirmationToken($tokenGenerator->generateToken());
         }
         $this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
         $user->setPasswordRequestedAt(new \DateTime());
         $this->container->get('fos_user.user_manager')->updateUser($user);
         return $this->container->get('templating')->renderResponse('FOSUserBundle:Resetting:checkEmail.html.' . $this->getEngine(), array('email' => $username));
     } else {
         return parent::sendEmailAction($request);
     }
 }
 public function resetAction(Request $request, $token)
 {
     if ($this->userAlreadyLoggedIn()) {
         $router = $this->container->get('router');
         return new RedirectResponse($router->generate('fos_user_profile_edit'), 302);
     }
     return parent::resetAction($request, $token);
 }
 /**
  * Reset user password
  */
 public function resetAction($token)
 {
     $return = parent::resetAction($token);
     if ($return instanceof RedirectResponse) {
         $user = $this->container->get('security.context')->getToken()->getUser();
         if ($user) {
             $discriminator = $this->container->get('nmn_user_discriminator');
             $discriminator->setClass(get_class($user), true);
         }
     }
     return $return;
 }
 /**
  * Reset user password
  */
 public function resetAction($token)
 {
     $return = parent::resetAction($token);
     if ($return instanceof RedirectResponse) {
         $user = $this->container->get('security.context')->getToken()->getUser();
         if (is_object($user) || $user instanceof UserInterface) {
             $dispatcher = $this->container->get('event_dispatcher');
             $event = new ManualLoginEvent($user);
             $dispatcher->dispatch('security.manual_login', $event);
         }
     }
     return $return;
 }
 /**
  * {@inheritdoc}
  */
 public function render($view, array $parameters = array(), Response $response = null)
 {
     return $this->renderDocumentResponse(parent::render($view, $parameters, $response));
 }
 /**
  * @ApiDoc(
  *  resource=false,
  *  section="Resetting",
  *  description="Reset user password",
  *  input="FOS\UserBundle\Form\Type\ResettingFormType"
  * )
  */
 public function resetAction(Request $request, $token)
 {
     return parent::resetAction($request, $token);
 }
Esempio n. 8
0
 /**
  * Reset user password
  */
 public function resetAction(Request $request, $token)
 {
     $event = new \SKCMS\FrontBundle\Event\PreRenderEvent($this->getRequest());
     $this->get('event_dispatcher')->dispatch(\SKCMS\FrontBundle\Event\SKCMSFrontEvents::PRE_RENDER, $event);
     return parent::resetAction($request, $token);
 }