コード例 #1
0
ファイル: UserManagerTest.php プロジェクト: Dren-x/mobitnew
 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);
 }
コード例 #2
0
ファイル: FacebookProvider.php プロジェクト: kishan530/trips
 /**
  * 
  * @param unknown $username
  * @throws UsernameNotFoundException
  * @return unknown
  */
 public function loadUserByUsername($username)
 {
     $user = $this->findUserByFbId($username);
     try {
         $fbdata = $this->facebook->api('/me');
     } catch (FacebookApiException $e) {
         $fbdata = null;
     }
     if (empty($user) and !empty($fbdata)) {
         $user = $this->userManager->findUserBy(array('email' => $fbdata['email']));
     }
     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;
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function updateAccessToken(UserInterface $user, $providerName, $token)
 {
     $providerName = ucfirst($providerName);
     $setter = "set{$providerName}AccessToken";
     $user->{$setter}($token);
     $this->userManager->updateUser($user);
 }
コード例 #4
0
 public function login(UserInterface $user)
 {
     $user->setLastLogin(new \DateTime());
     $this->userManager->updateUser($user);
     $this->loginManager->loginUser($this->providerKey, $user);
     return $user;
 }
コード例 #5
0
 /**
  * @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;
     }
 }
コード例 #6
0
 /**
  * @Route("/users/new", name="user_new")
  * @Template("BigfishUserBundle:Default:form.html.twig")
  */
 public function createAction(Request $request)
 {
     $user = $this->_security->getToken()->getUser();
     $entity = $this->_userManager->createUser();
     $form = $this->_formFactory->create(new UserType(), $entity);
     //        $this->_formFactory->create(, $data, $options);
     return array('form' => $form->createView());
 }
コード例 #7
0
 public function authorizeUser(UserInterface $authenticatedUser)
 {
     $user = $this->userManager->findUserByEmail($authenticatedUser->getEmail());
     if (null == $user) {
         throw new FailureAuthorizedException(401, "XSolve Google Auth couldn't authorize user. User doesn't exists");
     }
     return $user;
 }
コード例 #8
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);
 }
コード例 #9
0
 public function loadUserByUsername($username)
 {
     $user = $this->userManager->findUserByUsernameOrEmail($username);
     if (!$user instanceof UserInterface) {
         throw new UsernameNotFoundException(sprintf('No record found for user %s', $username));
     }
     return $user;
 }
コード例 #10
0
 public function testHRLogin()
 {
     $this->loadFixtures(array('Polcode\\Bundle\\RecruitmentBundle\\DataFixtures\\ORM\\LoadUserData', 'Polcode\\Bundle\\RecruitmentBundle\\DataFixtures\\ORM\\LoadProjectData'));
     $hr = $this->userManager->findUserByUsername('hr');
     $this->assertNotNull($hr, "W bazie brakuje użytkownika hr");
     $this->loginAs($hr, 'user');
     $client = $this->makeClient();
     $content1 = $this->fetchContent('/admin/polcode/recruitment/employee/list', false, true);
     $content2 = $this->fetchContent('/admin/polcode/recruitment/am/list', false, true);
     $content2 = $this->fetchContent('/admin/polcode/recruitment/project/list', false, true);
 }
コード例 #11
0
 public function validate($data, Constraint $constraint)
 {
     $id = $data->getId();
     $username = $data->getUsername();
     if ($id === null && $this->userManager->findUserByUsername($username)) {
         $this->context->addViolationAt('username', $constraint->message, array('%username%' => $username));
     }
     if ($id !== null && ($user = $this->userManager->findUserByUsername($username)) && $user->getId() !== $id) {
         $this->context->addViolationAt('username', $constraint->message, array('%username%' => $username));
     }
 }
コード例 #12
0
 /**
  * Gets or creates user profile, given user's ID
  *
  * @param integer $id ID
  *
  * @return UserProfile $profile
  */
 public function findOrCreateByUserID($id)
 {
     $profile = $this->repo->findByUserId($id);
     if ($profile) {
         $profile = $this->attachMissingUserProfileValues($profile);
     } else {
         $user = $this->userManager->findUserBy(array('id' => $id));
         $profile = $this->createUserProfileIfMissing($user);
     }
     return $profile;
 }
コード例 #13
0
ファイル: PersistableTest.php プロジェクト: apflieger/zigotoo
 /**
  * @return UserInterface|IdentityPersistableInterface
  */
 private function createUser()
 {
     /** @var UserInterface $user */
     $user = $this->userManager->createUser();
     $username = $this->getName() . rand();
     $user->setUsername($username);
     $user->setEmail($username . '@zigotoo.com');
     $user->setPlainPassword('test');
     $user->setEnabled(true);
     return $user;
 }
コード例 #14
0
 public function validate($data, Constraint $constraint)
 {
     $id = $data->getId();
     $email = $data->getEmail();
     if ($id === null && $this->userManager->findUserByEmail($email)) {
         $this->context->addViolationAt('email', $constraint->message, array('%email%' => $email));
     }
     if ($id !== null && ($user = $this->userManager->findUserByEmail($email)) && $user->getId() !== $id) {
         $this->context->addViolationAt('email', $constraint->message, array('%email%' => $email));
     }
 }
コード例 #15
0
 /**
  * @param array $googleAuthUser
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function build(array $googleAuthUser)
 {
     $user = $this->userManager->createUser();
     foreach ($googleAuthUser as $key => $value) {
         $methodName = "set" . Container::camelize($key);
         if (method_exists($user, $methodName)) {
             $user->{$methodName}($value);
         }
     }
     $user->setEmail($googleAuthUser['email']);
     $user->setUsername($googleAuthUser['email']);
     $user->setEnabled(1);
     $user->setPassword(time());
     return $user;
 }
コード例 #16
0
ファイル: EphpUserManager.php プロジェクト: ephp/acl
 /**
  * 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) {
         }
     }
 }
コード例 #17
0
ファイル: UserController.php プロジェクト: bzis/zomba
 /**
  * изменения профиля
  *
  * @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);
 }
コード例 #18
0
 public function updateCanonicalFields(UserInterface $user)
 {
     parent::updateCanonicalFields($user);
     if ($user instanceof User) {
         $user->getPublisher()->setEmail($user->getEmailCanonical());
     }
 }
コード例 #19
0
 /**
  * {@inheritDoc}
  */
 public function updatePassword(UserInterface $user)
 {
     if ($user instanceof UserWrapped) {
         parent::updatePassword($user->getInterfacedUser());
         return;
     }
     parent::updatePassword($user);
 }
コード例 #20
0
ファイル: OAuthUserProvider.php プロジェクト: blevoir/teamlol
 /**
  * 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;
 }
コード例 #21
0
ファイル: UserService.php プロジェクト: arnulfojr/qcharts
 /**
  * @param $username
  * @return User
  * @throws InstanceNotFoundException
  */
 protected function getUserFromUsername($username)
 {
     $user = $this->userManager->findUserByUsername($username);
     if (!$user) {
         throw new InstanceNotFoundException("User with the given username was not found: {$username}", 404);
     }
     return $user;
 }
コード例 #22
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);
 }
コード例 #23
0
ファイル: UserManager.php プロジェクト: symedit/symedit
 /**
  * @return UserInterface
  */
 public function createUser($admin = false)
 {
     $user = parent::createUser();
     $user->setProfile($this->createProfile($admin));
     $user->setAdmin($admin);
     $role = $admin ? 'ROLE_ADMIN' : 'ROLE_USER';
     $user->addRole($role);
     return $user;
 }
コード例 #24
0
 /**
  * @param null|User|string $user
  *                               string: Email or Username
  *                               User: User instance
  *                               null: CurrentUser if auth else placeholder
  *
  * @param int $size
  *
  * @return string
  */
 public function getGravatarImage($user = null, $size = 80)
 {
     $defaultImage = 'www.locastic.com/no-gravatar-image.jpg';
     if (null === $user) {
         if (false === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
             return $defaultImage;
         }
         $user = $this->securityContext->getToken()->getUser();
     } else {
         if (!$user instanceof User) {
             $user = $this->userManager->findUserByUsernameOrEmail($user);
         }
     }
     if (null !== $user->getGithubID()) {
         return $this->renderGithubGravatar($user, $size);
     }
     return $this->renderDefaultGravatar($user, $size);
 }
コード例 #25
0
 public function createOrReturnUser($email, $superAdmin = false, $password = '******', $firstName = 'TestUser', $lastName = 'UserProfile', $enabled = true)
 {
     $user = $this->userManager->findUserBy(array('email' => $email));
     if ($user == null) {
         // TODO: figure out how to customize this for each app's own UserManipulator
         $manipulatorMethod = $this->container->getParameter('crisistextline.user_profile.user_manipulator')['method'];
         $user = $this->userManipulator->{$manipulatorMethod}($email, $password, $firstName, $lastName, $enabled, $superAdmin);
     }
     return $user;
 }
コード例 #26
0
ファイル: ApiContext.php プロジェクト: EllynB/Incipio
 /**
  * @Then the password for user ":username" should be ":password"
  *
  * @param $username
  * @param $password
  */
 public function thePasswordForUserShouldBe($username, $password)
 {
     $user = $this->userManager->findUserByUsername($username);
     if (null === $user) {
         throw new \InvalidArgumentException(sprintf('No user with username %s can be found', $username));
     }
     $encoder = $this->encoderFactory->getEncoder($user);
     $valid = $encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt());
     PHPUnit::assertTrue($valid, sprintf('The password for user %s does not match %s', $username, $password));
 }
コード例 #27
0
 public function getUserByToken($token)
 {
     if (!$token instanceof HttpToken) {
         $token = $this->entityManager->getRepository('CoreSiteAPIAuthBundle:HttpToken')->getToken($token);
     }
     if (!$token instanceof HttpToken) {
         return false;
     }
     $user = $this->userManager->findUserBy(array('id' => $token->getUserId()));
     if (!$user instanceof UserInterface) {
         return false;
     }
     return $user;
 }
コード例 #28
0
ファイル: LoadCommand.php プロジェクト: nuffer/FundraisingDB
 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;
 }
コード例 #29
0
 /**
  * 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;
 }
コード例 #30
0
 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;
 }