本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}