@since 0.1

@param ApiUser $apiUser The ApiUser to log in as.

@throws UsageException
@return bool success
546580
public function login( ApiUser $apiUser ) {
		$this->logger->log( LogLevel::DEBUG, 'Logging in' );
		$credentials = $this->getLoginParams( $apiUser );
		$result = $this->postRequest( new SimpleRequest( 'login', $credentials ) );
		if ( $result['login']['result'] == "NeedToken" ) {
			$params = array_merge( [ 'lgtoken' => $result['login']['token'] ], $credentials );
			$result = $this->postRequest( new SimpleRequest( 'login', $params ) );
		}
		if ( $result['login']['result'] == "Success" ) {
			$this->isLoggedIn = $apiUser->getUsername();
			return true;
		}

		$this->isLoggedIn = false;
		$this->logger->log( LogLevel::DEBUG, 'Login failed.', $result );
		$this->throwLoginUsageException( $result );
		return false;
	}
102635
public function grantAccess($roleOrPermission, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();

        if (is_array($roleOrPermission) && $this->grantAccessByRoles($roleOrPermission, $user)) {
            return true;
        } else if (is_array($roleOrPermission) && $this->grantAccessByPermissions($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByRole($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByPermission($roleOrPermission, $user)) {
            return true;
        }

        return false;
    }
311169
private function validateResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() !== 200) {
            $responseData = json_decode((string) $response->getBody(), true);
            $code = isset($responseData['error']['code']) ? $responseData['error']['code'] : 0;
            $message = isset($responseData['error']['message']) ? $responseData['error']['message'] : $response->getReasonPhrase();

            throw new ApiException($message, $code, $responseData);
        }
    }
495447
public function saveApiCreds($apiUser, $apiPass)
    {
        $this->helper->saveConfigData(
            Config::XML_PATH_CONNECTOR_API_ENABLED,
            '1',
            'default',
            0
        );
        $this->helper->saveConfigData(
            Config::XML_PATH_CONNECTOR_API_USERNAME,
            $apiUser,
            'default',
            0
        );

        //Save encrypted password
        $this->helper->saveConfigData(
            Config::XML_PATH_CONNECTOR_API_PASSWORD,
            $this->helper->encryptor->encrypt($apiPass),
            'default',
            0
        );

        //Clear config cache
        $this->config->reinit();

        return true;
    }
1285098
public function setApiUri(string $apiUri): Client
    {
        $this->apiUri = $apiUri;
        $this->setUris();

        return $this;
    }
343154
public static function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $accessToken = new self();
        $accessToken->setUser($user);
        $accessToken->setClient($client);

        return $accessToken;
    }
915118
public static function authenticateWithPreset($preset, $api_id, $api_key) {
        return !is_null($api_id) && !is_null($api_key) &&
        Maestrano::with($preset)->param('api.id') == $api_id && Maestrano::with($preset)->param('api.key') == $api_key;
    }
984460
private function createHeaders($withUser = true)
    {
        if ($withUser === true) {
            return  '<apikey>'.$this->apikey.'</apikey>'.
                  '<username>'.$this->_login.'</username>'.
                  '<password>'.$this->_password.'</password>';
        } else {
            return '<apikey>'.$this->apikey.'</apikey>';
        }
    }
470491
private function resolveProfilePictureField(ApiUser $user): ?Field
    {
        $contentType = $user->getContentType();
        foreach ($user->getFields() as $field) {
            $fieldDef = $contentType->getFieldDefinition($field->fieldDefIdentifier);

            if ('ezimage' === $fieldDef->fieldTypeIdentifier) {
                return $field;
            }
        }

        return null;
    }
732566
private function useTokenHeaderChoice($apiTokenHeader)
    {
        if ($apiTokenHeader === true) {
            return Oauth2::TOKEN_ONLY_IN_HEADER;
        } elseif ($apiTokenHeader === false) {
            return Oauth2::TOKEN_ONLY_IN_GETPOST;
        } else {
            return Oauth2::TOKEN_AUTO_FIND;
        }
    }
883632
public function setApiUrl(string $apiUrl): Client
    {
        $this->apiUrl = $apiUrl;
        $this->setUris();

        return $this;
    }
1262037
public static function create($alias = null)
    {
        $card = new static();

        $response = (new AuthorizationBuilder(TransactionType::ALIAS, $card))
            ->withAlias(AliasAction::CREATE, $alias)
            ->execute();

        if ($response->responseCode === '00') {
            return $response->giftCard;
        }

        throw new ApiException($response->responseMessage);
    }
1035745
def api_user(request, userPk, key=None, hproPk=None):
    """"""

    if not check_api_key(request, key, hproPk):
        return HttpResponseForbidden

    if settings.PIAPI_STANDALONE:
        if not settings.PIAPI_REALUSERS:
            user = generate_user(pk=userPk)
            if user is None:
                return HttpResponseNotFound()
        else:
            user = get_object_or_404(DUser, pk=userPk)

        hproject = None
    else:
        from users.models import TechUser

        user = get_object_or_404(TechUser, pk=userPk)

        (_, _, hproject) = getPlugItObject(hproPk)

        user.ebuio_member = hproject.isMemberRead(user)
        user.ebuio_admin = hproject.isMemberWrite(user)
        user.subscription_labels = _get_subscription_labels(user, hproject)

    retour = {}

    # Append properties for the user data
    for prop in settings.PIAPI_USERDATA:
        if hasattr(user, prop):
            retour[prop] = getattr(user, prop)

    retour['id'] = str(retour['pk'])

    # Append the users organisation and access levels
    orgas = {}
    if user:
        limitedOrgas = []

        if hproject and hproject.plugItLimitOrgaJoinable:
            # Get List of Plugit Available Orgas first
            projectOrgaIds = hproject.plugItOrgaJoinable.order_by('name').values_list('pk', flat=True)
            for (orga, isAdmin) in user.getOrgas(distinct=True):
                if orga.pk in projectOrgaIds:
                    limitedOrgas.append((orga, isAdmin))
        elif hasattr(user, 'getOrgas'):
            limitedOrgas = user.getOrgas(distinct=True)

        # Create List
        orgas = [{'id': orga.pk, 'name': orga.name, 'codops': orga.ebu_codops, 'is_admin': isAdmin} for (orga, isAdmin)
                 in limitedOrgas]
    retour['orgas'] = orgas

    return HttpResponse(json.dumps(retour), content_type="application/json")
223920
public function userHasSocialLoginWithProvider($provider, $user)
    {
        return (bool) $this->socialLoginMapper->findBy([
            'provider' => $provider,
            'user_id'  => $user->getId()
        ]);
    }
90812
public function makeUserLoggedIn($user)
    {
        if (!is_array($user) && !is_object($user)) {
            $user = $this->getUser($user);
        } elseif (!($user instanceof UserDataInterface)) {
            $user = new UserData($user);
        }

        if ($user->isNull()) {
            return false;
        }

        return $this->getHandler()->login($user);
    }
1105301
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
1267743
public function logUser(\Symfony\Component\Security\Core\User\UserInterface $user)
    {
        // Here, "main" is the name of the firewall in your security.yaml
        $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
        $this->get('security.token_storage')->setToken($token);

        // Fire the login event
        $this->get('event_dispatcher')->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($token));
    }