Function creates relation for given user and social integration.

@param $user        User user entity
@param $serviceName string name of social service
@param $response    AbstractUser response data

@return mixed
762836
public function addSocialRelation(User $user, $serviceName, AbstractUser $response)
    {
        // create relation for new user and social integration
        return $this->newQB()->insert(
            [
                'user_id'    => $user->id,
                'social_id'  => $serviceName . '_' . $response->id,
                'created_at' => \DB::raw('NOW()')
            ]
        );
    }
107399
protected function jsonActionResponse(Response $response): ServiceResponse
    {
        // get the frontendData set by the Frontend plugin and remove unnecessary data
        $frontendData = $this->viewVars['frontendData'];
        unset($frontendData['Types']);
        $response = [
            'code' => 'success',
            'data' => [
                'frontendData' => $frontendData,
                'html' => $response->body(),
                'closeDialog' => $this->viewVars['closeDialog']
            ]
        ];

        return new ServiceResponse($response);
    }
367665
public function broadcastPage(ServerRequestInterface $request, UserInterface $user): ResponseInterface
    {
        $referer = $request->getHeaderLine('referer');

        $body    = $request->get('body', '');
        $subject = $request->get('subject', '');
        $to      = $request->get('to', '');
        $url     = $request->get('url', $referer);

        $to_names = $this->recipientUsers($to)
            ->map(static function (UserInterface $user): string {
                return $user->realName();
            });

        $title = $this->recipientDescription($to);

        $this->layout = 'layouts/administration';

        return $this->viewResponse('admin/broadcast', [
            'body'     => $body,
            'from'     => $user,
            'subject'  => $subject,
            'title'    => $title,
            'to'       => $to,
            'to_names' => $to_names,
            'url'      => $url,
        ]);
    }
1064442
public function createServicePhoneChannel($serviceId, $body)
    {
        list($response) = $this->createServicePhoneChannelWithHttpInfo($serviceId, $body);
        return $response;
    }
853772
public function handleResponse($response) {

        // No filter has been applied to this request.
        // Standard request, instantiate a single object.
        if(empty($this->filter)) {
            return $this->instantiateEntity($response);
        }

        // Filter applied.
        // Instantiate an object for each result returned.
        else {
            return array_map(function ($object) {
                return $this->instantiateEntity($object);
            }, $response->data);
        }

    }
882475
public function getChartAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        $ajax = (bool) $request->get('ajax');

        $xref  = $request->get('xref', '');
        $xref2 = $request->get('xref2', '');

        $individual1 = Individual::getInstance($xref, $tree);
        $individual2 = Individual::getInstance($xref2, $tree);

        $recursion = (int) $request->get('recursion', '0');
        $ancestors = (int) $request->get('ancestors', '0');

        $ancestors_only = (int) $tree->getPreference('RELATIONSHIP_ANCESTORS', static::DEFAULT_ANCESTORS);
        $max_recursion  = (int) $tree->getPreference('RELATIONSHIP_RECURSION', static::DEFAULT_RECURSION);

        $recursion = min($recursion, $max_recursion);

        if ($individual1 instanceof Individual) {
            Auth::checkIndividualAccess($individual1);
        }

        if ($individual2 instanceof Individual) {
            Auth::checkIndividualAccess($individual2);
        }

        Auth::checkComponentAccess($this, 'chart', $tree, $user);

        if ($individual1 instanceof Individual && $individual2 instanceof Individual) {
            if ($ajax) {
                return $this->chart($individual1, $individual2, $recursion, $ancestors);
            }

            /* I18N: %s are individual’s names */
            $title = I18N::translate('Relationships between %1$s and %2$s', $individual1->fullName(), $individual2->fullName());

            $ajax_url = $this->chartUrl($individual1, [
                'ajax'      => true,
                'xref2'     => $individual2->xref(),
                'recursion' => $recursion,
                'ancestors' => $ancestors,
            ]);
        } else {
            $title = I18N::translate('Relationships');

            $ajax_url = '';
        }

        return $this->viewResponse('modules/relationships-chart/page', [
            'ajax_url'          => $ajax_url,
            'ancestors'         => $ancestors,
            'ancestors_only'    => $ancestors_only,
            'ancestors_options' => $this->ancestorsOptions(),
            'individual1'       => $individual1,
            'individual2'       => $individual2,
            'max_recursion'     => $max_recursion,
            'module_name'       => $this->name(),
            'recursion'         => $recursion,
            'recursion_options' => $this->recursionOptions($max_recursion),
            'title'             => $title,
        ]);
    }
1184516
protected function createResponseAuthModel(BaseUser $user)
    {
        $user = $this->userService->updateUserRefreshToken($user);
        $authTokenModel = $this->authTokenService->createAuthTokenModel($user);

        return new ResponseAuthenticationModel($user, $authTokenModel, $user->getAuthRefreshModel());
    }
1169724
public function socialUpdate($provider, User $user)
    {
        $this->getProviderDetails($provider);

        // Get the users.
        $socialUser = $this->getSocialUser();

        // Update or create provider details.
        $this->updateFromProvider($user, $socialUser);

        return $socialUser;
    }
1088137
public function authenticateResponse(BaseUser $user, Response $response)
    {
        return $this->setCookieForResponse($response, $this->createResponseAuthModel($user));
    }
1109128
public function getUsername(Response $response)
    {
        foreach ($response->getAllAssertions() as $assertion) {
            $username = $this->getUsernameFromAssertion($assertion);
            if ($username) {
                return $username;
            }
        }

        return null;
    }
181736
public function create($serviceKey, $requestKey, array $parameters = [])
    {
        $config       = $this->getParamOrFail($this->config, $serviceKey);
        $service      = $this->getServiceParams($config);
        $request      = $this->getRequestParams($config, $requestKey, $service);
        $uri          = $this->buildUri($service['endpoint'], $request['path'], $request['query']);

        list($optionalParameters, $placeholders) = $this->separateParameters($request['body'], $parameters);

        $values       = array_values($parameters);
        $body         = $this->buildBody($request['body'], $request['headers'], $placeholders, $values, $optionalParameters);

        return $this->buildRequest(
            $request['method'],
            $this->replace($uri, $placeholders, $values),
            $this->replaceAll($request['headers'], $placeholders, $values),
            $body,
            $request['version'],
            $request['retries'],
            $request['options'],
            $serviceKey,
            $requestKey
        );
    }
1018476
public static function oneById($serviceName, $id)
	{
		if(!self::has($serviceName)) {
			return null;
		}
		/** @var ReadOneInterface $serviceInstance */
		$serviceInstance = self::get($serviceName);
		try {
			$result = $serviceInstance->oneById($id);
		} catch (NotFoundHttpException $e) {
			$result = null;
		}
		return $result;
	}
1366401
public function create($identity, $service, $token)
    {

        $params = array(
            'service' => $service,
            'token' => $token,
        );

        return $this->_user->post('account/identity/' . $identity . '/token', $params);
    }
154962
public function getResponsibleService(User $user, $deliveryId = null)
    {
        if (!isset($this->service))
        {
            /** @var DelegatedServiceHandler $handler */
            foreach ($this->getOption(self::SERVICE_HANDLERS) as $handler) {
                if (!is_a($handler, DelegatedServiceHandler::class)) {
                    throw new \common_exception_NoImplementation('Handler should be instance of DelegatorServiceHandler.');
                }
                $handler->setServiceLocator($this->getServiceLocator());
                if ($handler->isSuitable($user, $deliveryId)) {
                    $this->service = $handler;
                    break;
                }
            }
        }
        return $this->service;
    }
421773
private function createUser(SamlSpResponseToken $token)
    {
        if (null === $this->userCreator) {
            return null;
        }

        $user = $this->userCreator->createUser($token->getResponse());

        if ($user && false === $user instanceof UserInterface) {
            throw new \LogicException('User creator must return instance of UserInterface or null');
        }

        return $user;
    }
335620
public function getService($serviceName)
    {
        $serviceName = ltrim($serviceName, '@');
        if (!isset($this->registeredServices[$serviceName])) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
        }

        // Instantiate new service or get existing service instance
        if (!isset($this->instantiatedServices[$serviceName])) {
            $service = $this->instantiateService($serviceName);
        } else {
            $service = $this->instantiatedServices[$serviceName];
        }

        return $service;
    }
1248642
public function getUserFromTokenResponse($response)
    {
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = $this->parseAccessToken($response)
        ));

        $this->credentialsResponseBody = $response;

        if ($user instanceof User) {
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
        }

        return $user->setToken($token)
            ->setRefreshToken($this->parseRefreshToken($response))
            ->setExpiresIn($this->parseExpiresIn($response));
    }