yii\authclient\BaseClient::getUserAttributes PHP 메소드

getUserAttributes() 공개 메소드

public getUserAttributes ( ) : array
리턴 array list of user attributes
    public function getUserAttributes()
    {
        if ($this->_userAttributes === null) {
            $this->_userAttributes = $this->normalizeUserAttributes($this->initUserAttributes());
        }
        return $this->_userAttributes;
    }

Usage Example

예제 #1
1
 /**
  * Handle successful authentication
  * 
  * @param \yii\authclient\BaseClient $authClient
  * @return Response
  */
 public function onAuthSuccess(\yii\authclient\BaseClient $authClient)
 {
     $attributes = $authClient->getUserAttributes();
     // User already logged in - Add new authclient to existing user
     if (!Yii::$app->user->isGuest) {
         AuthClientHelpers::storeAuthClientForUser($authClient, Yii::$app->user->getIdentity());
         return $this->redirect(['/user/account/connected-accounts']);
     }
     // Login existing user
     $user = AuthClientHelpers::getUserByAuthClient($authClient);
     if ($user !== null) {
         return $this->login($user, $authClient);
     }
     if (!$authClient instanceof ApprovalBypass && !Yii::$app->getModule('user')->settings->get('auth.anonymousRegistration')) {
         Yii::$app->session->setFlash('error', Yii::t('UserModule.base', "You're not registered."));
         return $this->redirect(['/user/auth/login']);
     }
     // Check if E-Mail is given
     if (!isset($attributes['email'])) {
         Yii::$app->session->setFlash('error', "Missing E-Mail Attribute from AuthClient.");
         return $this->redirect(['/user/auth/login']);
     }
     if (!isset($attributes['id'])) {
         Yii::$app->session->setFlash('error', "Missing ID AuthClient Attribute from AuthClient.");
         return $this->redirect(['/user/auth/login']);
     }
     // Check if e-mail is already taken
     if (User::findOne(['email' => $attributes['email']]) !== null) {
         Yii::$app->session->setFlash('error', Yii::t('UserModule.base', 'User with the same email already exists but isn\'t linked to you. Login using your email first to link it.'));
         return $this->redirect(['/user/auth/login']);
     }
     // Try automatically create user & login user
     $user = AuthClientHelpers::createUser($authClient);
     if ($user !== null) {
         return $this->login($user, $authClient);
     }
     // Make sure we normalized user attributes before put it in session (anonymous functions)
     $authClient->setNormalizeUserAttributeMap([]);
     // Store authclient in session - for registration controller
     Yii::$app->session->set('authClient', $authClient);
     // Start registration process
     return $this->redirect(['/user/registration']);
 }
All Usage Examples Of yii\authclient\BaseClient::getUserAttributes