Esempio n. 1
0
 /**
  * Creates a PasswordLog object from the given user, storing the current time and the user's
  * current password hash.
  *
  * @param User $user
  * @param $ipAddr
  * @return PasswordLog
  */
 public static function make(User $user, $ipAddr)
 {
     $log = new PasswordLog();
     $log->setUser($user);
     $log->setIpAddress($ipAddr);
     $log->setPreviousHash($user->getPassword());
     return $log;
 }
 public function onResettingResetSuccess(FormEvent $event)
 {
     $user = $event->getForm()->getData();
     if ($user instanceof User) {
         $audit = AuditLog::make($user, 'password-reset', $event->getRequest()->getClientIp());
         $this->em->persist($audit);
         $plog = PasswordLog::make($user, $event->getRequest()->getClientIp());
         $this->em->persist($plog);
         $this->em->flush();
     }
 }
 protected function handleChangePwForm(User $user, Request $request, UserRepository $userRepo)
 {
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->container->get('fos_user.change_password.form.factory');
     $form = $formFactory->createForm();
     $form->setData($user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         // do this first, to log the previous password hash
         $passLog = PasswordLog::make($user, $request->getClientIp());
         $this->em()->persist($passLog);
         $this->em()->flush();
         /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
         $userManager = $this->container->get('fos_user.user_manager');
         $userManager->updateUser($user);
         $response = $this->redirectRoute('user_profile_edit', ['tab' => 'change-password']);
         $dispatcher = $this->get('event_dispatcher');
         $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
         $this->get('session')->getFlashBag()->get('success');
         // clear out existing success flash
         $this->flash('success', 'Your password has been updated.');
         return $response;
     }
     $passwordLogs = $this->repo('PasswordLog')->findBy(['user' => $user->getId()], ['dateChanged' => 'DESC']);
     return [$form, $passwordLogs];
 }