コード例 #1
0
 /**
  * Stores an authClient to an user record
  * 
  * @param \yii\authclient\BaseClient $authClient
  * @param User $user
  */
 public static function storeAuthClientForUser(ClientInterface $authClient, User $user)
 {
     $attributes = $authClient->getUserAttributes();
     if ($authClient instanceof interfaces\PrimaryClient) {
         $user->auth_mode = $authClient->getId();
         $user->save();
     } else {
         $auth = Auth::findOne(['source' => $authClient->getId(), 'source_id' => $attributes['id']]);
         /**
          * Make sure authClient is not double assigned
          */
         if ($auth !== null && $auth->user_id != $user->id) {
             $auth->delete();
             $auth = null;
         }
         if ($auth === null) {
             $auth = new \humhub\modules\user\models\Auth(['user_id' => $user->id, 'source' => (string) $authClient->getId(), 'source_id' => (string) $attributes['id']]);
             $auth->save();
         }
     }
 }