本文整理汇总了PHP中UserRepository::findOneBy方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRepository::findOneBy方法的具体用法?PHP UserRepository::findOneBy怎么用?PHP UserRepository::findOneBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository::findOneBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Using the given email finds the user and verifies it's password.
* If the user is not fund or if the password is wrong, it throws.
*
* @param array $credentials
* @throws AuthenticationException
* @return User|NULL
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
if (!($user = $this->userRepository->findOneBy(['email' => $username]))) {
throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
} elseif (!$user->verifyPassword($password)) {
throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
}
return $user;
}
示例2: startup
protected function startup()
{
parent::startup();
if ($this->key) {
if (($user = $this->userRepository->findOneBy(array('userKey' => $this->key))) === NULL) {
throw new BadRequestException();
}
$this->userRepository->delete($user);
$this->flashMessage('Byl jste odhlášen z newsletteru.', 'success');
$this->redirect('this', array('key' => NULL));
}
}
示例3: authenticate
/**
* @param array $credentials
* @return UserTable|Nette\Security\IIdentity
* @throws \Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$query = $this->userRepository->createQuery();
$query->where('@login', $username);
try {
$user = $this->userRepository->findOneBy($query);
} catch (NotFoundException $e) {
throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
}
if (!$user->isPasswordValid($password)) {
throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
}
return $user;
}
示例4: getUserByUsername
/**
* @return array
*/
public function getUserByUsername($username)
{
return $this->repository->findOneBy(array('username' => $username));
}