返回所有已经连接的社交媒体账户
@return Social[] Connected accounts ($provider => $account)
195849
public function getAccounts()
    {
        $connected = [];
        /** @var Social[] $accounts */
        $accounts = $this->hasMany(Social::className(), ['user_id' => 'id'])->all();
        /**
         * @var Social $account
         */
        foreach ($accounts as $account) {
            $connected[$account->provider] = $account;
        }

        return $connected;
    }
260056
public static function getAllProviders()
    {
        if (is_null(self::$providers)) {
            self::$providers = array();
            $plugins   = PluginManager::getInstance()->getPluginsLoadedAndActivated();
            foreach ($plugins as $plugin) {
                foreach (self::getLocationProviders($plugin) as $instance) {
                    self::$providers[] = $instance;
                }
            }
        }

        return self::$providers;
    }
390110
private function getAggregations()
    {
        $aggs = [];

        foreach ($this->aggregationProviders as $aggregationProvider) {
            $aggs[] = $aggregationProvider->getAggregation();
        }

        return $aggs;
    }
427511
public function getAllConnections()
    {
        $solrConnections = [];

        $solrConfigurations = $this->getAllConfigurations();
        foreach ($solrConfigurations as $solrConfiguration) {
            $solrConnections[] = $this->getConnectionFromConfiguration($solrConfiguration);
        }

        return $solrConnections;
    }
56810
public function getMutuals()
    {
        if (!isset($this->__mutuals)) {
            $ids = array_intersect($this->leaderIds->toArray(), $this->followerIds->toArray());
            $query = $this->getService('repos:people.person')->getQuery()->where('id', 'IN', $ids);

            $this->__mutuals = $query->toEntitySet();
        }

        return $this->__mutuals;
    }
1070562
public function getConnections()
    {
        $connections = [];
        foreach ($this->getConnectionNames() as $name) {
            $connections[$name] = $this->getConnection($name);
        }

        return $connections;
    }
127011
protected function socialSignon($provider)
    {
        $oUri       = Factory::service('Uri');
        $oLogger    = Factory::service('Logger');
        $oSession   = Factory::service('Session', 'nails/module-auth');
        $oSocial    = Factory::service('SocialSignOn', 'nails/module-auth');
        $oUserModel = Factory::model('User', 'nails/module-auth');

        //  Get the adapter, HybridAuth will handle the redirect
        $adapter  = $oSocial->authenticate($provider);
        $provider = $oSocial->getProvider($provider);

        // --------------------------------------------------------------------------

        //  Fetch the user's social profile and, if one exists, the local profile.
        try {

            $socialUser = $adapter->getUserProfile();

        } catch (Exception $e) {

            //  Failed to fetch from the provider, something must have gone wrong
            $oLogger->line('HybridAuth failed to fetch data from provider.');
            $oLogger->line('Error Code: ' . $e->getCode());
            $oLogger->line('Error Message: ' . $e->getMessage());

            if (empty($provider)) {
                $oSession->setFlashData(
                    'error',
                    'Sorry, there was a problem communicating with the network.'
                );
            } else {
                $oSession->setFlashData(
                    'error',
                    'Sorry, there was a problem communicating with ' . $provider['label'] . '.'
                );
            }

            if ($oUri->segment(4) == 'register') {
                $sRedirectUrl = 'auth/register';
            } else {
                $sRedirectUrl = 'auth/login';
            }

            if ($this->data['return_to']) {
                $sRedirectUrl .= '?return_to=' . urlencode($this->data['return_to']);
            }

            redirect($sRedirectUrl);
        }

        $oUser = $oSocial->getUserByProviderId($provider['slug'], $socialUser->identifier);

        // --------------------------------------------------------------------------

        /**
         * See if we already know about this user, react accordingly.
         * If a user already exists for this provider/identifier then it's logical
         * to spok them in, I mean, log them in - provided of course they aren't
         * already logged in, if they are then silly user. If no user is recognised
         * then we need to register them, providing, of course that registration is
         * enabled and that no one else on the system has their email address.
         * On that note, we need to respect APP_NATIVE_LOGIN_USING; if the provider
         * cannot satisfy this then we'll need to interrupt registration and ask them
         * for either a username or an email (or both).
         */

        if ($oUser) {

            if (isLoggedIn() && activeUser('id') == $oUser->id) {

                /**
                 * Logged in user is already logged in and is the social user.
                 * Silly user, just redirect them to where they need to go.
                 */

                $oSession->setFlashData('message', lang('auth_social_already_linked', $provider['label']));

                if ($this->data['return_to']) {
                    redirect($this->data['return_to']);
                } else {
                    redirect($oUser->group_homepage);
                }

            } elseif (isLoggedIn() && activeUser('id') != $oUser->id) {

                /**
                 * Hmm, a user was found for this Provider ID, but it's not the actively logged
                 * in user. This means that this provider account is already registered.
                 */

                $oSession->setFlashData('error', lang('auth_social_account_in_use', [$provider['label'], APP_NAME]));

                if ($this->data['return_to']) {
                    redirect($this->data['return_to']);
                } else {
                    redirect($oUser->group_homepage);
                }

            } else {

                //  Fab, user exists, try to log them in
                $oUserModel->setLoginData($oUser->id);
                $oSocial->saveSession($oUser->id);

                if (!$this->_login($oUser)) {

                    $oSession->setFlashData('error', $this->data['error']);

                    $sRedirectUrl = 'auth/login';

                    if ($this->data['return_to']) {
                        $sRedirectUrl .= '?return_to=' . urlencode($this->data['return_to']);
                    }

                    redirect($sRedirectUrl);
                }
            }

        } elseif (isLoggedIn()) {

            /**
             * User is logged in and it look's like the provider isn't being used by
             * anyone else. Go ahead and link the two accounts together.
             */

            if ($oSocial->saveSession(activeUser('id'), $provider)) {

                create_event('did_link_provider', ['provider' => $provider]);
                $oSession->setFlashData('success', lang('auth_social_linked_ok', $provider['label']));

            } else {
                $oSession->setFlashData('error', lang('auth_social_linked_fail', $provider['label']));
            }

            redirect($this->data['return_to']);

        } else {

            /**
             * Didn't find a user and the active user isn't logged in, assume they want
             * to register an account. I mean, who wouldn't, this site is AwEsOmE.
             */

            if (appSetting('user_registration_enabled', 'auth')) {

                $aRequiredData = [];
                $aOptionalData = [];

                //  Fetch required data
                switch (APP_NATIVE_LOGIN_USING) {

                    case 'EMAIL':
                        $aRequiredData['email'] = trim($socialUser->email);
                        break;

                    case 'USERNAME':
                        $aRequiredData['username'] = !empty($socialUser->username) ? trim($socialUser->username) : '';
                        break;

                    default:
                        $aRequiredData['email']    = trim($socialUser->email);
                        $aRequiredData['username'] = !empty($socialUser->username) ? trim($socialUser->username) : '';
                        break;
                }

                $aRequiredData['first_name'] = trim($socialUser->firstName);
                $aRequiredData['last_name']  = trim($socialUser->lastName);

                //  And any optional data
                if (checkdate($socialUser->birthMonth, $socialUser->birthDay, $socialUser->birthYear)) {

                    $aOptionalData['dob']          = [];
                    $aOptionalData['dob']['year']  = trim($socialUser->birthYear);
                    $aOptionalData['dob']['month'] = str_pad(trim($socialUser->birthMonth), 2, 0, STR_PAD_LEFT);
                    $aOptionalData['dob']['day']   = str_pad(trim($socialUser->birthDay), 2, 0, STR_PAD_LEFT);
                    $aOptionalData['dob']          = implode('-', $aOptionalData['dob']);
                }

                switch (strtoupper($socialUser->gender)) {

                    case 'MALE':
                        $aOptionalData['gender'] = 'MALE';
                        break;

                    case 'FEMALE':
                        $aOptionalData['gender'] = 'FEMALE';
                        break;
                }

                // --------------------------------------------------------------------------

                /**
                 * If any required fields are missing then we need to interrupt the registration
                 * flow and ask for them
                 */

                if (count($aRequiredData) !== count(array_filter($aRequiredData))) {

                    /**
                     * @TODO: One day work out a way of doing this so that we don't need to call
                     * the API again etc, uses unnecessary calls. Then again, maybe it *is*
                     * necessary.
                     */

                    $this->requestData($aRequiredData, $provider['slug']);
                }

                /**
                 * We have everything we need to create the user account However, first we need to
                 * make sure that our data is valid and not in use. At this point it's not the
                 * user's fault so don't throw an error.
                 */

                //  Check email
                if (isset($aRequiredData['email'])) {

                    $check = $oUserModel->getByEmail($aRequiredData['email']);

                    if ($check) {
                        $aRequiredData['email'] = '';
                        $requestData            = true;
                    }
                }

                // --------------------------------------------------------------------------

                if (isset($aRequiredData['username'])) {

                    /**
                     * Username was set using provider provided username, check it's valid if
                     * not, then request one. At this point it's not the user's fault so don't
                     * throw an error.
                     */

                    $check = $oUserModel->getByUsername($aRequiredData['username']);

                    if ($check) {
                        $aRequiredData['username'] = '';
                        $requestData               = true;
                    }

                } else {

                    /**
                     * No username, make one up for them, try to use the social_user username
                     * (as it might not have been set above), failing that use the user's name,
                     * failing THAT use a random string
                     */

                    if (!empty($socialUser->username)) {

                        $sUsername = $socialUser->username;

                    } elseif ($aRequiredData['first_name'] || $aRequiredData['last_name']) {

                        $sUsername = $aRequiredData['first_name'] . ' ' . $aRequiredData['last_name'];

                    } else {
                        $oDate     = Factory::factory('DateTime');
                        $sUsername = 'user' . $oDate->format('YmdHis');
                    }

                    $basename                  = url_title($sUsername, '-', true);
                    $aRequiredData['username'] = $basename;

                    $oUser = $oUserModel->getByUsername($aRequiredData['username']);

                    while ($oUser) {
                        $aRequiredData['username'] = increment_string($basename, '');
                        $oUser                     = $oUserModel->getByUsername($aRequiredData['username']);
                    }
                }

                // --------------------------------------------------------------------------

                //  Request data?
                if (!empty($requestData)) {
                    $this->requestData($aRequiredData, $provider->slug);
                }

                // --------------------------------------------------------------------------

                //  Handle referrals
                if ($oSession->getUserData('referred_by')) {
                    $aOptionalData['referred_by'] = $oSession->getUserData('referred_by');
                }

                // --------------------------------------------------------------------------

                //  Merge data arrays
                $data = array_merge($aRequiredData, $aOptionalData);

                // --------------------------------------------------------------------------

                //  Create user
                $newUser = $oUserModel->create($data);

                if ($newUser) {

                    /**
                     * Welcome aboard, matey
                     * - Save provider details
                     * - Upload profile image if available
                     */

                    $oSocial->saveSession($newUser->id, $provider);

                    if (!empty($socialUser->photoURL)) {

                        //  Has profile image
                        $imgUrl = $socialUser->photoURL;

                    } elseif (!empty($newUser->email)) {

                        //  Attempt gravatar
                        $imgUrl = 'http://www.gravatar.com/avatar/' . md5($newUser->email) . '?d=404&s=2048&r=pg';
                    }

                    if (!empty($imgUrl)) {

                        //  Fetch the image
                        //  @todo Consider streaming directly to the filesystem
                        $oHttpClient = Factory::factory('HttpClient');

                        try {

                            $oResponse = $oHttpClient->get($imgUrl);

                            if ($oResponse->getStatusCode() === 200) {

                                //  Attempt upload
                                $oCdn = Factory::service('Cdn', 'nails/module-cdn');

                                //  Save file to cache
                                $cacheFile = CACHE_PATH . 'new-user-profile-image-' . $newUser->id;

                                if (@file_put_contents($cacheFile, (string) $oResponse->getBody)) {

                                    $_upload = $oCdn->objectCreate($cacheFile, 'profile-images', []);

                                    if ($_upload) {

                                        $data                = [];
                                        $data['profile_img'] = $_upload->id;

                                        $oUserModel->update($newUser->id, $data);

                                    } else {
                                        $oLogger->line('Failed to upload user\'s profile image');
                                        $oLogger->line($oCdn->lastError());
                                    }
                                }
                            }

                        } catch (\Exception $e) {
                            $oLogger->line('Failed to upload user\'s profile image');
                            $oLogger->line($e->getMessage());
                        }
                    }

                    // --------------------------------------------------------------------------

                    //  Aint that swell, all registered! Redirect!
                    $oUserModel->setLoginData($newUser->id);

                    // --------------------------------------------------------------------------

                    //  Create an event for this event
                    create_event('did_register', ['method' => $provider], $newUser->id);

                    // --------------------------------------------------------------------------

                    //  Redirect
                    $oSession->setFlashData('success', lang('auth_social_register_ok', $newUser->first_name));

                    if (empty($this->data['return_to'])) {
                        $oUserGroupModel = Factory::model('UserGroup', 'nails/module-auth');
                        $group           = $oUserGroupModel->getById($newUser->group_id);
                        $sRedirectUrl    = $group->registration_redirect ? $group->registration_redirect : $group->default_homepage;
                    } else {
                        $sRedirectUrl = $this->data['return_to'];
                    }

                    redirect($sRedirectUrl);

                } else {

                    //  Oh dear, something went wrong
                    $sStatus  = 'error';
                    $sMessage = 'Sorry, something went wrong and your account could not be created.';
                    $oSession->setFlashData($sStatus, $sMessage);

                    $sRedirectUrl = 'auth/login';

                    if ($this->data['return_to']) {
                        $sRedirectUrl .= '?return_to=' . urlencode($this->data['return_to']);
                    }

                    redirect($sRedirectUrl);
                }

            } else {

                //  How unfortunate, registration is disabled. Redirect back to the login page
                $oSession->setFlashData('error', lang('auth_social_register_disabled'));

                $sRedirectUrl = 'auth/login';

                if ($this->data['return_to']) {
                    $sRedirectUrl .= '?return_to=' . urlencode($this->data['return_to']);
                }

                redirect($sRedirectUrl);
            }
        }
    }
387960
public function getMemberUsers() {

		$memberTable = CmnTables::getTableName( CmnTables::TABLE_GROUP_MEMBER );

		return $this->hasMany( User::class, [ 'id' => 'userId' ] )
			->viaTable( $memberTable, [ 'groupId' => 'id' ] );
	}
270106
public function graph()
    {
        $nodes = Scaffoldinterface::all()->map(function (Scaffoldinterface $entity) {
            return ['id' => $entity->id, 'label' => $entity->tablename];
        })->toJson();

        $edges = Relation::all()->map(function (Relation $relation) {
            return ['from' => $relation->scaffoldinterface_id, 'to' => $relation->to, 'label' => $relation->having];
        })->toJson();

        return view('scaffold-interface::graph', compact('nodes', 'edges'));
    }
750961
public function getCounts()
    {
        return array(
            'habbo' => count($this->habbo),
            'badges' => count($this->badges),
            'friends' => count($this->friends),
            'groups' => count($this->groups),
            'rooms' => count($this->rooms),
        );
    }
766515
public function getAllConnectedAccounts() {
		$accounts = array();
		foreach ($this->getAllAccountConnections() as $ac) {
			$accounts[] = $ac->getProperty('coid://accountgateways.cloudobjects.io/connectsTo');
		}
		return $accounts;
	}
93294
protected function getConnectApps() {
        if (!$this->_connectApps) {
            $this->_connectApps = new ConnectAppList($this->version, $this->solution['sid']);
        }

        return $this->_connectApps;
    }
715095
public function find($socialUser)
    {
        return SocialUser::where('social_id', $socialUser->id)
               ->where('social_type', $this->provider)->first();
    }
20634
public function users()
    {
        return $this->belongsToMany(Config::get('auth.providers.users.model'), Config::get('entrust.role_user_table'), Config::get('entrust.role_foreign_key'), Config::get('entrust.user_foreign_key'));
        // return $this->belongsToMany(Config::get('auth.model'), Config::get('entrust.role_user_table'));
    }
268605
protected function obtainConnectedServerList(): array
    {
        $serversList = $this->getServerList();
        $servers     = [];
        
        foreach ($serversList as $serverInfos) {
            $servers[] = $serverInfos['host'].':'.$serverInfos['port'];
        }
        
        return $servers;
    }
233019
public function members() : array
    {
        $members = [];

        if (!isset($this->info()->threadMembers) || $this->info()->threadMembers <= 0) return null;

        foreach ($this->info()->threadMembers as $member) {
            $members[] = new User($this->client, $member->onlineId);
        }

        return $members;
    }
729357
public function accessibleRelationsToArray()
	{
		$filtered  = [];
		$relations = $this->getArrayableRelations();

		/**
		 * @var $related \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Relations\Pivot
		 */
		foreach ($relations as $key => $related_collection) {
			if (! $this->access_authorizer->canAccess($key)) {
				continue;
			}

			if ($related_collection instanceof Pivot) {
				// Access test done above
				$filtered[$key] = $related_collection;
				continue;
			}

			// Many relation
			if ($related_collection instanceof Collection) {
				foreach ($related_collection as $index => $related) {
					$filtered[$key][$index] = $related->accessibleAttributesToArray();
				}
			} elseif ($related_collection instanceof LaravelModel) {
				// Single relation
				$filtered[$key] = $related_collection->accessibleAttributesToArray();
			}
		}

		return $filtered;
	}