Esempio n. 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();
         }
     }
 }
Esempio n. 2
0
 /**
  * @return type
  */
 public function getAuths()
 {
     return $this->hasMany(\humhub\modules\user\models\Auth::className(), ['user_id' => 'id']);
 }
Esempio n. 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()]);
 }