Exemplo n.º 1
0
 /**
  * Update the users password and/or salt
  *
  * @param User   $user
  * @param string $password New password
  * @param string $salt     If Ommitted, the salt will not be updated
  * @param bool   $flush    Flush the entity manager on completion
  */
 public function updateUserCredentials(User $user, $password, $salt = null, $flush = true)
 {
     if (!$salt) {
         $salt = $user->getSalt() ?: $this->generateSalt();
     }
     $encoder = $this->encoder_factory->getEncoder($user);
     $password = $encoder->encodePassword($password, $salt);
     $user->setPassword($password);
     $user->setSalt($salt);
     $this->entity_manager->persist($user);
     if ($flush) {
         $this->entity_manager->flush();
     }
 }
Exemplo n.º 2
0
 /**
  * Log the user in
  *
  * An InteractiveLoginEvent will be fired if you include the request
  *
  * @param User    $user     User entity
  * @param string  $password Users password
  * @param Request $request  Optionally provide the Request object to dispatch an InteractiveLoginEvent
  */
 public function doLogin(User $user, $password, Request $request = null)
 {
     $token = new UsernamePasswordToken($user->getUsername(), $password, $this->provider_key, $user->getRoles());
     $this->token_storage->setToken($token);
     // Fire the login event
     if ($request) {
         $event = new InteractiveLoginEvent($request, $token);
         $this->event_dispatcher->dispatch("security.interactive_login", $event);
     }
 }