예제 #1
0
 /**
  * Attach OAuth sign-in provider account to existing user
  *
  * @param FOSUserInterface      $user
  * @param UserResponseInterface $response
  *
  * @return FOSUserInterface
  */
 protected function updateUserByOAuthUserResponse(FOSUserInterface $user, UserResponseInterface $response)
 {
     $providerName = $response->getResourceOwner()->getName();
     $providerNameSetter = 'set' . ucfirst($providerName) . 'Id';
     $user->{$providerNameSetter}($response->getUsername());
     if (!$user->getPassword()) {
         // generate unique token
         $secret = md5(uniqid(rand(), true));
         $user->setPassword($secret);
     }
     return $user;
 }
예제 #2
0
 /**
  * Attach OAuth sign-in provider account to existing user
  *
  * @param FOSUserInterface      $user
  * @param UserResponseInterface $response
  *
  * @return FOSUserInterface
  */
 protected function updateUserByOAuthUserResponse(FOSUserInterface $user, UserResponseInterface $response)
 {
     $providerName = $response->getResourceOwner()->getName();
     $providerNameSetter = 'set' . ucfirst($providerName) . 'Id';
     $user->{$providerNameSetter}($response->getUsername());
     /** Is for accept OAuth connexion without password **/
     if (!$user->getPassword()) {
         $secret = md5(uniqid(rand(), true));
         $user->setPassword($secret);
     }
     return $user;
 }
 /**
  * add the symfony-login "manually".
  * 
  * use the symfony token-storage for the generated UsernamePasswordToken 
  * to access the (logged in) user later (e.g. to check for roles or permissions)
  * 
  * the given $passwordHash must match the encrypted password in the user-object
  * 
  * before and after the generation/setting of the token, the events "secotrust.user_login.before" 
  * and "secotrust.user_login.after" are called, if some EventListeners are configured
  *
  * @param \FOS\UserBundle\Model\UserInterface $user
  * @param $passwordHash
  */
 private function userLoginAction(\FOS\UserBundle\Model\UserInterface $user, $passwordHash)
 {
     // call the pre-login-event
     $event = new Event();
     $this->dispatcher->dispatch('secotrust.user_login.before', $event);
     if ($user->getPassword() !== $passwordHash) {
         // stop the login-action, when the password doesn't match
         return;
     }
     $token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles());
     $this->token_storage->setToken($token);
     // call the post-login-event
     $event = new Event();
     $this->dispatcher->dispatch('secotrust.user_login.after', $event);
 }