public function loadUserByUsername($username)
	{
		$user = $this->findUserByFbId($username);

		try {
			$fbdata = $this->facebook->api('/me');
		} catch (FacebookApiException $e) {
			$fbdata = null;
		}

		if (!empty($fbdata)) {
			if (empty($user)) {
				$user = $this->userManager->createUser();
				$user->setEnabled(true);
				$user->setPassword('');
			}

			// TODO use http://developers.facebook.com/docs/api/realtime
			$user->setFBData($fbdata);

			if (count($this->validator->validate($user, 'Facebook'))) {
				// TODO: the user was found obviously, but doesnt match our expectations, do something smart
				throw new UsernameNotFoundException('The facebook user could not be stored');
			}
			$this->userManager->updateUser($user);
		}

		if (empty($user)) {
			throw new UsernameNotFoundException('The user is not authenticated on facebook');
		}

		return $user;
	}
 public function login(UserInterface $user)
 {
     $user->setLastLogin(new \DateTime());
     $this->userManager->updateUser($user);
     $this->loginManager->loginUser($this->providerKey, $user);
     return $user;
 }
 /**
  * @inheritdoc
  */
 public function updateAccessToken(UserInterface $user, $providerName, $token)
 {
     $providerName = ucfirst($providerName);
     $setter = "set{$providerName}AccessToken";
     $user->{$setter}($token);
     $this->userManager->updateUser($user);
 }
 /**
  * @see OAuth2\IOAuth2GrantExtension::checkGrantExtension
  */
 public function checkGrantExtension(IOAuth2Client $client, array $inputData, array $authHeaders)
 {
     if (!isset($inputData['facebook_access_token'])) {
         return false;
     }
     $this->facebookSdk->setDefaultAccessToken($inputData['facebook_access_token']);
     try {
         // Try to get the user with the facebook token from Open Graph
         $fbData = $this->facebookSdk->get('/me?fields=email,id,first_name,last_name,name,name_format');
         if (!$fbData instanceof \Facebook\FacebookResponse) {
             return false;
         }
         // Check if a user match in database with the facebook id
         $user = $this->userManager->findUserBy(['facebookId' => $fbData->getDecodedBody()['id']]);
         // If none found, try to match email
         if (null === $user && isset($fbData->getDecodedBody()['email'])) {
             $user = $this->userManager->findUserBy(['email' => $fbData->getDecodedBody()['email']]);
         }
         // If no user found, register a new user and grant token
         if (null === $user) {
             // TODO: Create new user
             return false;
         } else {
             // Else, return the access_token for the user
             // Associate user with facebookId
             $user->setFacebookId($fbData->getDecodedBody()['id']);
             $this->userManager->updateUser($user);
             return array('data' => $user);
         }
     } catch (\FacebookApiExceptionion $e) {
         return false;
     }
 }
Example #5
0
 public function testUpdateUser()
 {
     $user = $this->getUser();
     $this->om->expects($this->once())->method('persist')->with($this->equalTo($user));
     $this->om->expects($this->once())->method('flush');
     $this->userManager->updateUser($user);
 }
Example #6
0
 public function sendWelcomeEmail(User $user)
 {
     $token = $this->tokenGenerator->generateToken();
     $link = $this->router->generate('fos_user_registration_register', array('token' => $token), true);
     $this->mailer->sendMail($this->translator->trans('jwkh.publishers.email.welcome.subject', array(), null, $user->getPublisher()->getCongregation()->getDefaultLocale()), '*****@*****.**', $user->getEmail(), $this->translator->trans('jwkh.publishers.email.welcome.body', array('%link%' => $link), null, $user->getPublisher()->getCongregation()->getDefaultLocale()));
     $user->setConfirmationToken($token);
     $this->userManager->updateUser($user);
 }
Example #7
0
 public function testModifiedAt()
 {
     $user = $this->createUser();
     $this->timeService->lockNow();
     $this->userManager->updateUser($user);
     // A la création de l'entité, createdAt et modifiedAt ont la même valeur, 'now'
     $this->assertEquals($this->timeService->now(), $user->getModifiedAt());
     //modification du user
     $user->setPlainPassword('modified');
     //enregistrement du user une seconde plus tard
     $this->timeService->lockNow($this->timeService->now()->add(new DateInterval('PT1S')));
     // Simule un sleep(1)
     $this->userManager->updateUser($user);
     $this->assertEquals($this->timeService->now(), $user->getModifiedAt());
     $this->assertGreaterThan($user->getCreatedAt(), $user->getModifiedAt());
 }
Example #8
0
 /**
  * изменения профиля
  *
  * @ApiDoc(
  *     section="User API",
  *     input="Vifeed\UserBundle\Form\ProfileType",
  *     statusCodes={
  *         200="Returned when successful",
  *         400="Returned when the something was wrong",
  *         403="Returned when the user is not authorized to use this method"
  *     }
  * )
  *
  * @Rest\Patch("users/current")
  *
  * @return Response
  */
 public function patchUserAction()
 {
     /** @var User $user */
     $user = $this->getUser();
     $request = $this->container->get('request');
     if ($request->request->has('profile')) {
         $oldEmail = $user->getEmail();
         $form = $this->createForm(new ProfileType(), $user)->submit($request, false);
         if ($form->isValid()) {
             if ($user->getEmail() !== $oldEmail) {
                 $user->setEmailConfirmed(false);
                 $event = new FormEvent($form, $request);
                 $this->eventDispatcher->dispatch(VifeedUserEvents::CHANGE_EMAIL_SUCCESS, $event);
             }
         }
     } elseif ($request->request->has('change_password')) {
         $form = $this->createForm(new ChangePasswordFormType(), $user)->submit($request);
     } else {
         throw new BadRequestHttpException();
     }
     if ($form->isValid()) {
         $this->userManager->updateUser($user);
         $view = new View('');
     } else {
         $view = new View($form, 400);
     }
     return $this->handleView($view);
 }
Example #9
0
 /**
  * Updates a user.
  *
  * @param UserInterface $user
  * @param Boolean       $andFlush Whether to flush the changes (default true)
  */
 public function updateUser(UserInterface $user, $andFlush = true)
 {
     parent::updateUser($user, $andFlush);
     if ($this->container->getParameter('ephp_acl.access_log.enable')) {
         $accessClassName = $this->accessClass;
         try {
             $request = $this->container->get('request');
             //                \Ephp\UtilityBundle\Utility\Debug::vd($request);
             $check_ip = $this->container->getParameter('ephp_acl.access_log.check_ip');
             if ($check_ip) {
                 $_access = $this->objectManager->getRepository($accessClassName);
                 /* @var $_access Ephp\ACLBundle\Model\BaseAccessLogRepository */
                 $_access->checkIp($user, $request->server->get('REMOTE_ADDR'));
             }
             $access = new $accessClassName();
             /* @var $access \Ephp\ACLBundle\Model\BaseAccessLog */
             $access->setUser($user);
             /* @var $request \Symfony\Component\HttpFoundation\Request */
             $access->setIp($request->server->get('REMOTE_ADDR'));
             foreach ($request->cookies as $name => $cookie) {
                 $access->addCookie($name, $cookie);
             }
             $access->setLoggedAt(new \DateTime());
             $access->addNote('user_agent', $request->server->get('HTTP_USER_AGENT'));
             $access->addNote('accept_language', $request->server->get('HTTP_ACCEPT_LANGUAGE'));
             $this->objectManager->persist($access);
             $this->objectManager->flush();
             //            \Ephp\UtilityBundle\Utility\Debug::pr($request->server);
             $request->getSession()->set('access.log', $access->getId());
         } catch (CheckIpException $e) {
             throw $e;
         } catch (\Exception $e) {
         }
     }
 }
Example #10
0
 /**
  * Ad-hoc creation of user
  *
  * @param UserResponseInterface $response
  *
  * @return User
  */
 protected function createUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->manager->createUser();
     // set default values taken from OAuth sign-in provider account
     if (null !== ($email = $response->getEmail())) {
         $user->setEmail($email);
         $user->setUsername($email);
         $user->setPlainPassword(md5(uniqid()));
     }
     $user->setEnabled(true);
     // Conservation de l'id
     $providerName = $response->getResourceOwner()->getName();
     $providerNameSetter = 'set' . ucfirst($providerName) . 'Id';
     $user->{$providerNameSetter}($response->getResponse()['id']);
     $this->manager->updateUser($user);
     return $user;
 }
 /**
  * {@inheritdoc}
  */
 public function updateUser(UserInterface $user, $andFlush = true)
 {
     if ($user instanceof UserWrapped) {
         parent::updateUser($user->getInterfacedUser(), $andFlush);
         return;
     }
     parent::updateUser($user, $andFlush);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function updateUser(UserInterface $user, $andFlush = true)
 {
     // Extract email part before the `@` character to use it as username is username not set
     if (null === $user->getUsername()) {
         $user->setUsername(substr($user->getEmail(), 0, strpos($user->getEmail(), '@')));
     }
     // Call parent after as does not override parent and parent do the flush
     parent::updateUser($user, $andFlush);
 }
Example #13
0
 private function createUser($username, $email, $admin = false)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setPlainPassword($username);
     $user->setEmail($email);
     $user->addRole('ROLE_USER');
     if ($admin) {
         $user->setSuperAdmin(true);
         $user->setEnabled(true);
         $user->setLocked(false);
     }
     $this->userManager->updateUser($user);
     return $user;
 }
 /**
  * Retourne un utilisateur de la base en fonction de l'utilisateur facebook
  * Si il n'existe pas, on en créée un
  * @param  GraphUser $user [description]
  * @return [type]          [description]
  */
 public function getUserFromFacebook(GraphUser $user)
 {
     $email = $user->getEmail();
     if (is_null($email)) {
         throw new \Exception('Facebook user does not share email', 400);
     }
     // Get user from email
     $fos_user = $this->user_manager->findUserByEmail($email);
     // Create user if necessary
     if (is_null($fos_user)) {
         $fos_user = $this->user_manager->createUser();
     }
     $fos_user->setEnabled(true);
     $fos_user->setEmail($email);
     $fos_user->setFirstName($user->getFirstName());
     $fos_user->setLastName($user->getLastName());
     $fos_user->setRoles([$this->user_role]);
     $fos_user->setFacebookId($user->getId());
     $fos_user->setLocale(substr($user->getProperty('locale'), 0, 2));
     $fos_user->setTimezone($user->getTimezone());
     $this->user_manager->updateCanonicalFields($fos_user);
     $this->user_manager->updateUser($fos_user);
     return $fos_user;
 }
 public function loadUserByUsername($username)
 {
     $user = $this->findUserByTwitterUsername($username);
     $this->twitterOauth->setOAuthToken($this->session->get('access_token'), $this->session->get('access_token_secret'));
     try {
         $info = $this->twitterOauth->get('account/verify_credentials');
     } catch (\Exception $e) {
         $info = null;
     }
     if (!empty($info)) {
         if (isset($info->errors) && is_array($info->errors) && count($info->errors)) {
             throw new AuthenticationException($info->errors[0]->message, $info->errors[0]->code);
         }
         if (empty($user)) {
             $user = $this->userManager->createUser();
             $user->setEnabled(true);
             $user->setLocked(false);
         }
         $username = $info->screen_name;
         $user->setTwitterID($info->id);
         $user->setTwitterUsername($username);
         $email = $user->getEmail();
         if (is_null($email) || strlen(trim($email)) === 0) {
             $user->setEmail($username . '@twitter.com');
         }
         if (null === $user->getUsername()) {
             $user->setUsername($username);
         }
         $user->setFullName($info->name);
         $this->userManager->updateUser($user);
     }
     if (empty($user)) {
         throw new UsernameNotFoundException('The user is not authenticated on twitter');
     }
     return $user;
 }
Example #16
0
 /**
  * Enregistrement d'un utilisateur en base
  * @author Benjamin Levoir <*****@*****.**>
  */
 public function createUser(\CoreBundle\Entity\User $user)
 {
     $user->setEnabled(true);
     $this->manager->updateUser($user);
     $this->em->flush();
 }
Example #17
0
 /**
  * Updates a user.
  *
  * @param UserInterface $user
  * @param Boolean       $andFlush Whether to flush the changes (default true)
  */
 public function updateUser(UserInterface $user, $andFlush = true)
 {
     $this->updateCanonicalFields($user);
     $this->enforceUsername($user);
     parent::updateUser($user, $andFlush);
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function save($entity, $andFlush = true)
 {
     parent::updateUser($entity, $andFlush);
 }
 /**
  * @param $user
  *
  * @return bool
  */
 public function onSuccess($user)
 {
     $this->userManager->updateUser($user);
     return true;
 }
 function it_should_persist_applicant(UserManager $userManager, Applicant $applicant)
 {
     $userManager->updateUser($applicant, true)->shouldBeCalled();
     $this->persistApplicant($applicant)->shouldReturn(null);
 }