コード例 #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();
         }
     }
 }
コード例 #2
0
ファイル: User.php プロジェクト: kreativmind/humhub
 /**
  * @return type
  */
 public function getAuths()
 {
     return $this->hasMany(\humhub\modules\user\models\Auth::className(), ['user_id' => 'id']);
 }
コード例 #3
0
 /**
  * Removes Authclient for a user
  * 
  * @param \yii\authclient\BaseClient $authClient
  * @param User $user
  */
 public static function removeAuthClientForUser(ClientInterface $authClient, User $user)
 {
     Auth::deleteAll(['user_id' => $user->id, 'source' => (string) $authClient->getId()]);
 }