Ejemplo n.º 1
0
 /**
  * Displays page where user can create new account that will be connected to social account.
  * @param  integer $account_id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionConnect($account_id)
 {
     $account = $this->finder->findAccountById($account_id);
     if ($account === null || $account->getIsConnected()) {
         throw new NotFoundHttpException();
     }
     /** @var User $user */
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'connect']);
     if ($user->load(\Yii::$app->request->post()) && $user->create()) {
         $account->user_id = $user->id;
         $account->save(false);
         \Yii::$app->user->login($user, $this->module->rememberFor);
         return $this->goBack();
     }
     return $this->render('connect', ['model' => $user, 'account' => $account]);
 }
Ejemplo n.º 2
0
 /**
  * Disconnects a network account from user.
  * @param  integer $id
  * @return \yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  * @throws \yii\web\ForbiddenHttpException
  */
 public function actionDisconnect($id)
 {
     $account = $this->finder->findAccountById($id);
     if ($account === null) {
         throw new NotFoundHttpException();
     }
     if ($account->user_id != \Yii::$app->user->id) {
         throw new ForbiddenHttpException();
     }
     $account->delete();
     return $this->redirect(['networks']);
 }