/** * Delete user account connection * @param $userAuthId * @return false|int * @throws */ public static function disconnect($userAuthId) { if (\Yii::$app->user->isGuest) { throw new UnauthorizedHttpException(\Yii::t('user', 'Guests can not disconnect accounts')); } $user = \Yii::$app->user->identity; if (empty($user->password) && count($user->userAuths) < 2) { throw new ErrorException(\Yii::t('user', 'Can not disconnect single authentication method. Please fill email and password and try again')); } $userAuth = UserAuth::findOne($userAuthId); if ($userAuth->user_id != \Yii::$app->user->id) { throw new UnauthorizedHttpException(\Yii::t('user', 'Сan not disconnect a foreign account')); } return $userAuth->delete(); }