Creates a social profile from a HybridAuth adapter profile

@param \Hybrid_User_Profile	$adapter_profile
@param User					$user

@return Profile
10702
protected function createProfileFromAdapterProfile($adapter_profile, $user)
	{
		$ProfileModel = $this->config['db']['profilemodel'];
		$attributes['provider'] = $this->provider;

		// @todo use config value for foreign key name
		$attributes['user_id'] = $user->id;

		$profile = new $ProfileModel($attributes);
		$profile = $this->applyAdapterProfileToExistingProfile($adapter_profile, $profile);

		return $profile;
	}
120079
public function createSocialUser($socialUser, $userId)
    {
        return SocialUser::create([
            'user_id'     => $userId,
            'social_id'   => $socialUser->id,
            'social_type' => $this->provider,
            'nickname'    => $socialUser->nickname,
            'name'        => $socialUser->name,
            'email'       => $socialUser->email,
            'avatar'      => $socialUser->avatar,
            'meta'        => json_encode($socialUser),
        ]);
    }
787483
function getUserProfile()
    {
        $this->api->api_base_url    = $this->getEndpoint().'/2.0/';

        $data = $this->api->api( "users/profile.json?apikey=".$this->api->access_token );

        if ( ! isset( $data->global_user_id ) ){
            throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
        }

        $this->user->profile->identifier    = @ $data->global_user_id;
        $this->user->profile->displayName   = @ $data->name;
        $this->user->profile->email         = @ $data->email;
        $this->user->profile->photoURL      = @ $data->avatar;

        $data = $this->api->api( "helper/account-details.json?apikey=".$this->api->access_token );

        $this->user->profile->webSiteURL    = @ $data->contact->url;
        $this->user->profile->firstName     = @ $data->contact->fname;
        $this->user->profile->lastName      = @ $data->contact->lname;
        $this->user->profile->address       = @ $data->contact->address1;
        if(isset($data->contact->address2) && strlen($data->contact->address2)){
            $this->user->profile->address .= ', '.$data->contact->address2;
        }
        $this->user->profile->zip           = @ $data->contact->zip;
        $this->user->profile->city          = @ $data->contact->city;
        $this->user->profile->country       = @ $data->contact->country;
        $this->user->profile->phone         = @ $data->contact->phone;

        return $this->user->profile;
    }
223920
public function userHasSocialLoginWithProvider($provider, $user)
    {
        return (bool) $this->socialLoginMapper->findBy([
            'provider' => $provider,
            'user_id'  => $user->getId()
        ]);
    }
1056859
protected function registerUserAdapter()
    {
        $this->app->bind('adapter.user', function ($app) {
            return new User($app['config']);
        });

        $this->app->alias('adapter.user', User::class);
    }
693163
public function authenticate()
    {
        $hybridAuth = $this->getHybridAuth();
        /* @var $adapter \Hybrid_Provider_Model */
        $adapter = $hybridAuth->authenticate($this->_provider);

        $userProfile = $adapter->getUserProfile();
        $email = isset($userProfile->emailVerified) && !empty($userProfile->emailVerified)
              ? $userProfile->emailVerified
              : $userProfile->email;
       
       
        $forceSave = false;
        $user = $this->getRepository()->findByProfileIdentifier($userProfile->identifier, $this->_provider, ['allowDeactivated' => true]);

        if (!$user) {
            $forceSave = true;
            $user = $this->getRepository()->create();
        }
       
       
        $currentInfo = $user->getProfile($this->_provider);
        $socialData = [];
        
        try {
            $socialProfile = $this->socialProfilePlugin->fetch($this->_provider);
            
            if (false !== $socialProfile) {
                $socialData = $socialProfile->getData();
            }
        } catch (\InvalidArgumentException $e) {}
        
        $newInfo = [
            'auth' => (array) $userProfile,
            'data' => $socialData,
        ];
       
        if ($forceSave || $currentInfo != $newInfo) {
            $dm = $this->getRepository()->getDocumentManager();
            $userInfo = $user->getInfo();
            
            if ('' == $userInfo->getEmail()) {
                $userInfo->setEmail($email);
            }
            
            $userInfo->setFirstName($userProfile->firstName);
            $userInfo->setLastName($userProfile->lastName);
            $userInfo->setBirthDay($userProfile->birthDay);
            $userInfo->setBirthMonth($userProfile->birthMonth);
            $userInfo->setBirthYear($userProfile->birthYear);
            $userInfo->setPostalCode($userProfile->zip);
            $userInfo->setCity($userProfile->city);
            $userInfo->setStreet($userProfile->address);
            $userInfo->setPhone($userProfile->phone);
            $userInfo->setGender($userProfile->gender);
            
            // $user->setLogin($email); // this may cause duplicate key exception
            $user->addProfile($this->_provider, $newInfo);

            $dm->persist($user);
            // make sure all ids are generated and user exists in database.
            $dm->flush();

            /*
            * This must be after flush because a newly created user has no id!
            */
            if ($forceSave || (!$userInfo->getImage() && $userProfile->photoURL)) {
                // get user image
                if ('' != $userProfile->photoURL) {
                    $client = new \Zend\Http\Client($userProfile->photoURL, array('sslverifypeer' => false));
                    $response = $client->send();
                    $file = new GridFSFile();
                    $file->setBytes($response->getBody());

                    $userImage = new UserImage();
                    $userImage->setName($userProfile->lastName.$userProfile->firstName);
                    $userImage->setType($response->getHeaders()->get('Content-Type')->getFieldValue());
                    $userImage->setUser($user);
                    $userImage->setFile($file);
                    $userInfo->setImage($userImage);
                    $dm->persist($userImage);
                    //$this->getRepository()->store($user->info);
                }

                // We have to flush again
                $dm->flush();
            }
        }
        
       
        return new Result(Result::SUCCESS, $user->getId(), array('firstLogin' => $forceSave, 'user' => $user));
    }
329391
public function logConnectPlatformListAction(User $user, Request $request)
    {
        $this->checkAdminToolAccess();
        $isAdmin = $this->authorization->isGranted('ROLE_ADMIN');
        $hiddenFilters = $isAdmin ?
            [] :
            ['hiddenFilters' => [
                'organizations' => array_map(function (Organization $organization) {
                    return $organization->getUuid();
                }, $user->getAdministratedOrganizations()->toArray()),
            ]];

        return new JsonResponse(
            $this->finder->search(LogConnectPlatform::class, array_merge(
                $request->query->all(),
                $hiddenFilters
            ))
        );
    }
1102945
private function getAdapter(string $adapter = null, array $params, SymfonyStyle $inputOutput): Adapter
    {
        $adapterName = $adapter ?? $inputOutput->askQuestion(new AdapterChoice());
        $adapterName = strtolower($adapterName);

        if (empty($params)) {
            $questionGenerator = new AdapterQuestionProvider();
            foreach ($questionGenerator->getQuestionsFor($adapterName) as $question) {
                $params[] = $inputOutput->askQuestion($question);
            }
        }

        return $this->adapterFactory->build($adapterName, $params);
    }
1170582
public function create( $user, $config = [] ) {

		$snsUser		= $config[ 'snsUser' ];
		$accessToken	= $config[ 'accessToken' ];

		$snsProfileToSave = $this->getModelObject();

		$snsProfileToSave->userId	= $user->id;
		$snsProfileToSave->type		= SnsConnectGlobal::SNS_TYPE_TWITTER;
		$snsProfileToSave->snsId	= strval( $snsUser->id );
		$snsProfileToSave->token	= $accessToken;
		$snsProfileToSave->secret	= $snsUser->secret;
		$snsProfileToSave->data		= json_encode( $snsUser );

		// Create SnsProfile
		$snsProfileToSave->save();

		// Return SnsProfile
		return $snsProfileToSave;
	}
1340706
public function getAuthAdapter(\Gems_User_User $user, $password)
    {
        $config = $this->project->getLdapSettings();

        $adapter = new LdapAdapter();

        // \MUtil_Echo::track($config);
        foreach ($config as $server) {
            $adapter->setOptions([$server]);

            if (isset($server['accountDomainNameShort'])) {
                $userName = $server['accountDomainNameShort'] . '\\' . $user->getLoginName();
            } else {
                $userName = $user->getLoginName();
            }

            $adapter->setUsername($userName)
                    ->setPassword($password);
        }

        return $adapter;
    }
261977
public static function convertMapToUserProfile($userProfileMap)
    {
        $userId = $userProfileMap[self::USER_ID_KEY];
        $experimentBucketMap = array();
        foreach ($userProfileMap[self::EXPERIMENT_BUCKET_MAP_KEY] as $experimentId => $decisionMap) {
            $variationId = $decisionMap[self::VARIATION_ID_KEY];
            $experimentBucketMap[$experimentId] = new Decision($variationId);
        }

        return new UserProfile($userId, $experimentBucketMap);
    }
1122516
public function registerSocialUser($socialUser, $provider)
    {
        // Create the new user
        $user = $this->user->create($this->getUserFromSocial($socialUser));

        if (! $user) {
            return $user;
        }

        // Fire the registering event.
        event(new UserRegistering($user, $socialUser));

        // Add the extra details needed to finish them.
        // Add the user details.
        $this->userDetails->create($this->getUserDetailsFromSocial($socialUser, $user));

        // Assign the user to the default group
        $user->assignRole(config('jumpgate.users.default_role'));

        // Add the user's social account details.
        $user->addSocial($socialUser, $provider);

        // If we do not require activation, set the user as active.
        if (! config('jumpgate.users.require_email_activation')) {
            $user->updateActivationDetails();
        }

        // Fire the registered event.
        event(new UserRegistered($user, $socialUser));

        return $user;
    }
1115800
public function getNonPlatformRolesForUser(User $user, $executeQuery = true)
    {
        return $this->roleRepo->findNonPlatformRolesForUser($user, $executeQuery);
    }
674983
public function createFromConfig(Repository $config, $adapter = null)
    {
        $options = $this->getOptions($config);

        return $this->createFromOptions($options, $adapter);
    }
519844
public function createOrganization(User $user)
    {
        $organization = new $this->organizationClass;
        $organization->setOwner($user);
        $organization->addUser($user);

        $role = new Role;
        $role->setRoles(array('ROLE_ORGANIZATION_OWNER'));
        $role->setUser($user);
        $role->setOrganization($organization);

        $contact = $user->getContact();

        if (!$contact) {
            $contact = new Contact;
            $user->setContact($contact);
        }

        $organizationContact = clone $user->getContact();
        $organization->setContact($organizationContact);
        $user->setActiveOrganization($organization);
        $user->setActiveRole($role);

        $this->dm->persist($user);
        $this->dm->persist($role);
        $this->dm->persist($contact);
        $this->dm->persist($organizationContact);
        $this->dm->persist($organization);
        $this->dm->flush();

        $this->eventDispatcher->dispatch(
            'wc_user.organization.create',
            new GenericEvent('wc_user.organization.create', array(
                'notifyUser'                => $user,
                'notifyOrganizationTrigger' => $organization,
                'notifyOrganizations'       => [$organization],
                'data'                      => [
                    'organization' => $organization
                ]
            ))
        );

        return $organization;
    }
803372
public function createTokenRequest(User $user, $issuer)
    {
        $idAttribution = $user->getCurrentAttribution() ? $user->getCurrentAttribution()->getId() : null;

        return (new TokenRequest())
            ->setUsername($user->getUserName())
            ->setAttributionId($idAttribution)
            ->setIssuer($issuer);
    }
1131838
protected final function createAuthManager(array $options = [], IAuthAdapter $adapter = null, IAuthStorage $storage = null)
    {
        return $this->getAuthFactory()
            ->createManager($options, $adapter, $storage);
    }