本文整理汇总了PHP中Symfony\Component\Security\Core\User\UserInterface类的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface类的具体用法?PHP UserInterface怎么用?PHP UserInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isEqualTo
public function isEqualTo(UserInterface $user)
{
if ($this->username == $user->getUsername()) {
return true;
}
return false;
}
示例2: logUser
private function logUser(UserInterface $user, $password)
{
$token = new UsernamePasswordToken($user, $password, 'secured_area', $user->getRoles());
$request = $this->getRequest();
$session = $request->getSession();
$session->set('_security_secured_area', serialize($token));
}
示例3: getSecret
/**
* {@inheritdoc}
*/
protected function getSecret(UserInterface $user)
{
if ($user instanceof AdvancedApiUserInterface) {
return $user->getApiKeys();
}
return parent::getSecret($user);
}
示例4: updateLastLogin
/**
* Update the users last login.
*
* @param UserInterface $user
*/
protected function updateLastLogin($user)
{
if ($user instanceof BaseUser) {
$user->setLastLogin(new \DateTime());
$this->entityManager->flush();
}
}
示例5: authenticateUser
private function authenticateUser(UserInterface $user)
{
$providerKey = 'secured_area';
// your firewall name
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
$this->getSecurityContext()->setToken($token);
}
示例6: isEqualTo
public function isEqualTo(UserInterface $user)
{
if (!$user instanceof CorredorUser || $this->password !== $user->getPassword() || $this->salt !== $user->getSalt() || $this->username !== $user->getUsername()) {
return false;
}
return true;
}
示例7: isEqualTo
/**
* {@inheritDoc}
*/
public function isEqualTo(UserInterface $user)
{
if ($user instanceof FacebookUser && $user->getId() === $this->getId()) {
return true;
}
return false;
}
示例8: validateDigest
/**
* {@InheritDoc}
*
* @throws NonceExpiredException
*/
public function validateDigest(WsseUserToken $wsseToken, UserInterface $user)
{
$created = $wsseToken->created;
$nonce = $wsseToken->nonce;
$digest = $wsseToken->digest;
$secret = $user->getPassword();
// Check created time is not too far in the future (leaves 5 minutes margin)
if (strtotime($created) > time() + 300) {
throw new WsseAuthenticationException(sprintf('Token created date cannot be in future (%d seconds in the future).', time() - strtotime($created)));
}
// Expire timestamp after 5 minutes
if (strtotime($created) < time() - 300) {
throw new WsseAuthenticationException(sprintf('Token created date has expired its 300 seconds of validity (%d seconds).', strtotime($created) - time()));
}
// Validate that the nonce is *not* used in the last 10 minutes
// if it has, this could be a replay attack
if (file_exists($this->cacheDir . '/' . $nonce) && file_get_contents($this->cacheDir . '/' . $nonce) + 600 > time()) {
throw new NonceExpiredException('Previously used nonce detected.');
}
// If cache directory does not exist we create it
if (!is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0777, true);
}
file_put_contents($this->cacheDir . '/' . $nonce, time());
// Validate Secret
$expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
if (!StringUtils::equals($expected, $digest)) {
throw new WsseAuthenticationException('Token digest is not valid.');
}
return true;
}
示例9: checkAuthentication
/**
* {@inheritdoc}
*/
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
{
$currentUser = $token->getUser();
if ($currentUser instanceof UserInterface) {
if ($currentUser->getPassword() !== $user->getPassword()) {
throw new BadCredentialsException('The credentials were changed from another session.');
}
} else {
if (!($presentedPassword = $token->getCredentials())) {
throw new BadCredentialsException('The presented password cannot be empty.');
}
$client = $this->clientFactory->build('en');
$request = CustomerLoginRequest::ofEmailAndPassword($token->getUser(), $presentedPassword);
$response = $request->executeWithClient($client);
if ($response->isError()) {
throw new BadCredentialsException('The presented password is invalid.');
}
$result = $request->mapResponse($response);
$customer = $result->getCustomer();
if ($currentUser !== $customer->getEmail()) {
throw new BadCredentialsException('The presented password is invalid.');
}
$this->session->set('customer.id', $customer->getId());
}
}
示例10: refreshUser
public function refreshUser(UserInterface $user)
{
if (!$user instanceof User) {
throw new UnsupportedUserException("Instances of {get_class({$user})} are not supported");
}
return $this->loadUserByUsername($user->getUsername());
}
示例11: refreshUser
/**
* {@inheritDoc}
*/
public function refreshUser(UserInterface $user)
{
if (null === ($refreshedUser = $this->repository->findOneByUsername($user->getUsername()))) {
throw new UsernameNotFoundException(sprintf('User with id %s not found', json_encode($user->getId())));
}
return $refreshedUser;
}
示例12: isGranted
/**
*
* @param string $attribute
* @param Club $club
* @param UserInterface $user
* @return boolean
*/
protected function isGranted($attribute, $club, $user = null)
{
switch ($attribute) {
case self::VIEW:
if (!$club->isPrivate()) {
return true;
}
// make sure there is a user object (i.e. that the user is logged in)
if (!$user instanceof UserInterface) {
return false;
}
if (in_array('ROLE_ADMIN', $user->getRoles())) {
return true;
}
break;
case self::EDIT:
// make sure there is a user object (i.e. that the user is logged in)
if (!$user instanceof UserInterface) {
return false;
}
foreach ($club->getAdministrators() as $administrator) {
if ($administrator->getId() == $user->getId()) {
return true;
}
}
if (in_array('ROLE_ADMIN', $user->getRoles())) {
return true;
}
return false;
case self::CREATE:
break;
}
return false;
}
示例13: isEqualTo
public function isEqualTo(UserInterface $user)
{
if (!$user instanceof LdapUser || $user->getUsername() !== $this->username || $user->getEmail() !== $this->email || count(array_diff($user->getRoles(), $this->roles)) > 0 || $user->getDn() !== $this->dn) {
return false;
}
return true;
}
示例14: login
public function login(UserInterface $user)
{
$user->setLastLogin(new \DateTime());
$this->userManager->updateUser($user);
$this->loginManager->loginUser($this->providerKey, $user);
return $user;
}
示例15: equals
public function equals(UserInterface $account)
{
if ($this->getUsername() == $account->getUsername()) {
return true;
}
return false;
}