当前位置: 首页>>代码示例>>PHP>>正文


PHP UserManagerInterface::findUserByUsername方法代码示例

本文整理汇总了PHP中FOS\UserBundle\Model\UserManagerInterface::findUserByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP UserManagerInterface::findUserByUsername方法的具体用法?PHP UserManagerInterface::findUserByUsername怎么用?PHP UserManagerInterface::findUserByUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FOS\UserBundle\Model\UserManagerInterface的用法示例。


在下文中一共展示了UserManagerInterface::findUserByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke(Request $request)
 {
     if ($this->container->hasParameter('partkeepr.auth.allow_password_change') && $this->container->getParameter('partkeepr.auth.allow_password_change') === false) {
         throw new PasswordChangeNotAllowedException();
     }
     $user = $this->userService->getUser();
     if (!$request->request->has('oldpassword') && !$request->request->has('newpassword')) {
         throw new \Exception('old password and new password need to be specified');
     }
     $FOSUser = $this->userManager->findUserByUsername($user->getUsername());
     if ($FOSUser !== null) {
         $encoder = $this->encoderFactory->getEncoder($FOSUser);
         $encoded_pass = $encoder->encodePassword($request->request->get('oldpassword'), $FOSUser->getSalt());
         if ($FOSUser->getPassword() != $encoded_pass) {
             throw new OldPasswordWrongException();
         }
         $this->userManipulator->changePassword($user->getUsername(), $request->request->get('newpassword'));
     } else {
         if ($user->isLegacy()) {
             if ($user->getPassword() !== md5($request->request->get('oldpassword'))) {
                 throw new OldPasswordWrongException();
             }
             $user->setNewPassword($request->request->get('newpassword'));
             $this->userService->syncData($user);
         } else {
             throw new \Exception('Cannot change password for LDAP users');
         }
     }
     $user->setPassword('');
     $user->setNewPassword('');
     return $user;
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:32,代码来源:ChangePasswordAction.php

示例2: findUserByUsernameOrThrowException

 /**
  * Finds a user by his username and throws an exception if we can't find it.
  *
  * @param string $username
  *
  * @throws \InvalidArgumentException When user does not exist
  *
  * @return UserInterface
  */
 private function findUserByUsernameOrThrowException($username)
 {
     $user = $this->userManager->findUserByUsername($username);
     if (!$user) {
         throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
     }
     return $user;
 }
开发者ID:Jheengut,项目名称:linuxcounter.new,代码行数:17,代码来源:UserManipulator.php

示例3: loadUserByUsername

 /**
  * {@inheritDoc}
  */
 public function loadUserByUsername($username)
 {
     // Compatibility with FOSUserBundle < 2.0
     if (class_exists('FOS\\UserBundle\\Form\\Handler\\RegistrationFormHandler')) {
         return $this->userManager->loadUserByUsername($username);
     }
     return $this->userManager->findUserByUsername($username);
 }
开发者ID:Aukraiser,项目名称:YetAnotherTweetsAnalyzer,代码行数:11,代码来源:FOSUBUserProvider.php

示例4: getNbUnreadByUsername

 public function getNbUnreadByUsername($username)
 {
     $nb = apc_fetch('nbm.' . $username);
     if (false === $nb) {
         $user = $this->userManager->findUserByUsername($username);
         $nb = $this->updateNbUnread($participant);
     }
     return $nb;
 }
开发者ID:hotfics,项目名称:lichess-old,代码行数:9,代码来源:Cache.php

示例5: reverseTransform

 /**
  * Transforms a username string into a UserInterface instance.
  *
  * @param string $value Username
  *
  * @return UserInterface the corresponding UserInterface instance
  *
  * @throws UnexpectedTypeException if the given value is not a string
  */
 public function reverseTransform($value)
 {
     if (null === $value || '' === $value) {
         return null;
     }
     if (!is_string($value)) {
         throw new UnexpectedTypeException($value, 'string');
     }
     return $this->userManager->findUserByUsername($value);
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:19,代码来源:UserToUsernameTransformer.php

示例6: createModelInstance

 protected function createModelInstance()
 {
     $message = parent::createModelInstance();
     if ($to = $this->request->query->get('to')) {
         if ($recipient = $this->userManager->findUserByUsername($to)) {
             $message->setRecipient($recipient);
         }
     }
     return $message;
 }
开发者ID:hotfics,项目名称:lichess-old,代码行数:10,代码来源:NewThreadMessageFormFactory.php

示例7: getUserByUnPw

 /**
  * @param string $un
  * @param string $pw
  * @return \FOS\UserBundle\Model\UserInterface|null
  */
 function getUserByUnPw($un, $pw)
 {
     $result = null;
     if ($un && $pw) {
         $user = $this->_fosUserManager->findUserByUsername($un);
         if ($user && $this->isPasswordValid($user, $pw)) {
             $result = $user;
         }
     }
     return $result;
 }
开发者ID:appsco,项目名称:component-share,代码行数:16,代码来源:FosUserProvider.php

示例8: getPrincipalByPath

 /**
  * Returns a specific principal, specified by it's path.
  * The returned structure should be the exact same as from
  * getPrincipalsByPrefix.
  *
  * @param string $path
  * @param bool   $getObject
  *
  * @return array|GroupInterface|UserInterface|void
  *
  * @throws Exception
  */
 public function getPrincipalByPath($path, $getObject = false)
 {
     $name = str_replace('principals/', '', $path);
     // get username from path-string, if string contains additional slashes (e.g. admin/calendar-proxy-read)
     if (!(strpos($name, '/') === false)) {
         $name = substr($name, 0, strpos($name, '/'));
     }
     $user = $this->user_manager->findUserByUsername($name);
     if ($user === null) {
         if (!$this->group_manager) {
             return;
         }
         // search in group-manager
         $group = $this->group_manager->findGroupByName($name);
         if ($group === null) {
             return;
         }
         if ($getObject === true) {
             return $group;
         }
         return $this->getPrincipalArray($group, true);
     }
     if ($getObject === true) {
         return $user;
     }
     return $this->getPrincipalArray($user, true);
 }
开发者ID:bartv2,项目名称:SecotrustSabreDavBundle,代码行数:39,代码来源:PrincipalBackend.php

示例9: getUniqueUserName

 /**
  * Attempts to get a unique username for the user.
  *
  * @param string $name
  *
  * @return string Name, or empty string if it failed after all the iterations.
  */
 protected function getUniqueUserName($name)
 {
     $i = 0;
     $testName = $name;
     do {
         $user = $this->userManager->findUserByUsername($testName);
     } while ($user !== null && $i < $this->iterations && ($testName = $name . ++$i));
     return $user !== null ? '' : $testName;
 }
开发者ID:ismailbaskin,项目名称:HWIOAuthBundle,代码行数:16,代码来源:FOSUBRegistrationFormHandler.php

示例10: demote

 /**
  * Demotes the given user.
  *
  * @param string $username
  */
 public function demote($username)
 {
     $user = $this->userManager->findUserByUsername($username);
     if (!$user) {
         throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
     }
     $user->setSuperAdmin(false);
     $this->userManager->updateUser($user);
 }
开发者ID:nightchiller,项目名称:UserBundle,代码行数:14,代码来源:UserManipulator.php

示例11: deleteFOSUser

 /**
  * Deletes an user from the FOSUser system
  * @param User $user
  */
 public function deleteFOSUser(User $user)
 {
     if ($user->getProvider()->getType() !== self::BUILTIN_PROVIDER) {
         return;
     }
     $FOSUser = $this->userManager->findUserByUsername($user->getUsername());
     if ($FOSUser !== null) {
         $this->userManager->deleteUser($FOSUser);
     }
 }
开发者ID:fulcrum3d,项目名称:PartKeepr,代码行数:14,代码来源:UserService.php

示例12: delete

 /**
  * Removes the User from the database.
  *
  * @param \Hal\Resource $resource
  *
  * @throws NotFoundHttpException if no user with the given id could be found.
  *
  * @return void
  */
 public function delete(Resource $resource)
 {
     $data = $resource->toArray();
     $user = $this->userManager->findUserByUsername($data['username']);
     if (!$user) {
         $errorMessage = $this->translator->trans('error.user_not_found', array('%username%' => $data['username']));
         throw new NotFoundHttpException($errorMessage);
     }
     $this->userManager->deleteUser($user);
 }
开发者ID:ingewikkeld,项目名称:rest-user-bundle,代码行数:19,代码来源:User.php

示例13: SamlUser

 function it_load_user_by_username(SamlAuth $auth, UserInterface $user, UserManagerInterface $userManager)
 {
     $auth->getAttributes()->shouldBeCalled();
     $auth->getUsername()->shouldBeCalled();
     $auth->isAuthenticated()->shouldBeCalled();
     $user->getUsername()->shouldBeCalled();
     $user->getRoles()->shouldBeCalled();
     $userManager->findUserByUsername(self::USERNAME)->shouldBeCalled();
     $samlUser = new SamlUser('user@domain.com', ['ROLE_USER'], []);
     $this->loadUserByUsername('user@domain.com')->shouldBeLike($samlUser);
 }
开发者ID:aulasoftwarelibre,项目名称:CeepsUserBundle,代码行数:11,代码来源:FosBackendSamlUserProviderSpec.php

示例14: validateUserPass

 /**
  * Checks if username and password are valid. (Checked by the FOSUserManager)
  * Returns.
  *
  * @param $username
  * @param $passwordHash
  *
  * @return bool
  */
 public function validateUserPass($username, $passwordHash)
 {
     $user = $this->user_manager->findUserByUsername($username);
     if (is_null($user)) {
         return false;
     }
     if ($passwordHash === $user->getPassword()) {
         //            $this->userLoginAction($user, $passwordHash);
         return true;
     }
     return false;
 }
开发者ID:bartv2,项目名称:SecotrustSabreDavBundle,代码行数:21,代码来源:AuthBackend.php

示例15: removeRole

 /**
  * Removes role from the given user.
  *
  * @param string $username
  * @param string $role
  *
  * @return Boolean true if role was removed, false if user didn't have the role
  */
 public function removeRole($username, $role)
 {
     $user = $this->userManager->findUserByUsername($username);
     if (!$user) {
         throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
     }
     if (!$user->hasRole($role)) {
         return false;
     }
     $user->removeRole($role);
     $this->userManager->updateUser($user);
     return true;
 }
开发者ID:StanFrag,项目名称:CCM-Stage,代码行数:21,代码来源:UserManipulator.php


注:本文中的FOS\UserBundle\Model\UserManagerInterface::findUserByUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。