Esempio n. 1
0
 protected function authSuccess($client)
 {
     /** @var \yii\authclient\BaseClient $client */
     $this->socialServiceId = SocialService::classNameToId($client->className());
     if ($this->socialServiceId === 0) {
         throw new ServerErrorHttpException("SocialService unknown");
     }
     // first find user service on this id
     $userAttributes = $client->getUserAttributes();
     $this->serviceId = $userAttributes['id'];
     //! @todo Add caching here based on commonTag
     $this->userService = UserService::find()->where(['service_id' => $this->serviceId, 'social_service_id' => $this->socialServiceId])->one();
     return parent::authSuccess($client);
 }
 public function run($service_id)
 {
     /** @var User $user */
     $user = Yii::$app->user->identity;
     if ($user === null) {
         throw new ServerErrorHttpException("No user identity found");
     }
     $userService = UserService::findOne(['social_service_id' => $service_id, 'user_id' => $user->id]);
     if ($userService === null) {
         throw new NotFoundHttpException();
     }
     if ($userService->delete()) {
         Yii::$app->session->addFlash('success', Yii::t('users', 'Service has been deleted'));
     } else {
         Yii::$app->session->addFlash('error', Yii::t('users', 'Service has not been deleted'));
     }
     $this->controller->redirect(['@manage-social']);
 }
Esempio n. 3
0
 public function getServices()
 {
     return $this->hasMany(UserService::className(), ['user_id' => 'id']);
 }