public function actionUnbind($id) { $key = UserOauthKey::findOne(['user_id' => Yii::$app->user->id, 'provider_id' => UserOauthKey::getAvailableClients()[$id]]); if (!$key) { Yii::$app->session->setFlash('error', 'Ключ не найден'); } else { $key->delete(); Yii::$app->session->setFlash('success', 'Ключ удален'); } return $this->redirect(Yii::$app->request->referrer); }
/** * Outputs client auth link. * @param ClientInterface $client external auth client instance. * @param string $text link text, if not set - default value will be generated. * @param array $htmlOptions link HTML options. * @throws InvalidConfigException on wrong configuration. */ public function clientLink($client, $text = null, array $htmlOptions = []) { echo Html::beginTag('div', ['class' => 'col-xs-6']); $exists = UserOauthKey::findOne(['user_id' => Yii::$app->user->id, 'provider_id' => UserOauthKey::getAvailableClients()[$client->getId()]]); if ($exists) { $button = Html::a('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <span class="hidden-md">' . Yii::t('yii', 'Delete') . '</span>', Url::toRoute(['/user/auth/unbind', 'id' => $client->getId()]), ['class' => 'btn btn-danger btn-sm', 'onclick' => '$(this).off("click"); return true;']); } else { $viewOptions = $client->getViewOptions(); if (isset($viewOptions['popupWidth'])) { $htmlOptions['data-popup-width'] = $viewOptions['popupWidth']; } if (isset($viewOptions['popupHeight'])) { $htmlOptions['data-popup-height'] = $viewOptions['popupHeight']; } $htmlOptions['class'] = 'btn btn-success btn-sm'; $button = Html::a('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="hidden-md">' . Yii::t('users', 'ADD') . '</span>', $this->createClientUrl($client), $htmlOptions); } echo Html::tag('span', $button, ['class' => 'auth-icon ' . $client->getName(), 'style' => 'padding-left: 40px; margin-bottom: 10px;']); echo Html::endTag('div'); }