OAuth (part 9 draft)
This commit is contained in:
parent
29e11e915f
commit
410879c522
4 changed files with 53 additions and 12 deletions
|
@ -10,16 +10,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace ForkBB\Models\Pages\Profile;
|
||||
|
||||
use ForkBB\Core\Image;
|
||||
use ForkBB\Core\Validator;
|
||||
use ForkBB\Core\Exceptions\MailException;
|
||||
use ForkBB\Models\Page;
|
||||
use ForkBB\Models\Pages\Profile;
|
||||
use ForkBB\Models\Pages\RegLogTrait;
|
||||
use ForkBB\Models\User\User;
|
||||
use function \ForkBB\__;
|
||||
use function \ForkBB\num;
|
||||
use function \ForkBB\size;
|
||||
|
||||
class OAuth extends Profile
|
||||
{
|
||||
|
@ -100,7 +95,7 @@ class OAuth extends Profile
|
|||
}
|
||||
|
||||
/**
|
||||
* Подготавливает данные для шаблона списка аккаунтов
|
||||
* Подготавливает данные для шаблона аккаунта
|
||||
*/
|
||||
public function action(array $args, string $method): Page
|
||||
{
|
||||
|
@ -135,13 +130,32 @@ class OAuth extends Profile
|
|||
$this->c->Lang->load('validator');
|
||||
|
||||
if ('POST' === $method) {
|
||||
$v = $this->c->Validator->reset()
|
||||
->addValidators([
|
||||
])->addRules([
|
||||
'token' => 'token:EditUserOAuthAction',
|
||||
'confirm' => 'checkbox',
|
||||
'delete' => 'string',
|
||||
])->addAliases([
|
||||
])->addArguments([
|
||||
'token' => $args,
|
||||
])->addMessages([
|
||||
]);
|
||||
|
||||
if (
|
||||
$v->validation($_POST)
|
||||
&& '1' === $v->confirm
|
||||
) {
|
||||
if (! empty($v->delete)) {
|
||||
$this->c->providerUser->deleteAccount($this->curUser, $name, $userId);
|
||||
|
||||
return $this->c->Redirect->page('EditUserOAuth', $args)->message('Account removed');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->c->Redirect->page('EditUserOAuthAction', $args)->message('No confirm redirect');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$this->crumbs = $this->crumbs(
|
||||
[
|
||||
$this->c->Router->link('EditUserOAuthAction', $args),
|
||||
|
|
|
@ -112,7 +112,7 @@ class ProviderUser extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Удаляет записи удаляемых пользователей
|
||||
* Удаляет OAuth аккаунты удаляемых пользователей
|
||||
*/
|
||||
public function delete(User ...$users): void
|
||||
{
|
||||
|
@ -132,6 +132,27 @@ class ProviderUser extends Model
|
|||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет один OAuth аккаунт данного пользователя (без проверки наличия)
|
||||
*/
|
||||
public function deleteAccount(User $user, string $name, string $userId): void
|
||||
{
|
||||
if ($user->isGuest) {
|
||||
throw new RuntimeException('User expected, not guest');
|
||||
}
|
||||
|
||||
$vars = [
|
||||
':uid' => $user->id,
|
||||
':name' => $name,
|
||||
':userId' => $userId,
|
||||
];
|
||||
$query = 'DELETE
|
||||
FROM ::providers_users
|
||||
WHERE uid=?i:uid AND pr_name=?s:name AND pu_uid=?s:userId';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Вовращает список записей по пользователю
|
||||
*/
|
||||
|
|
|
@ -104,3 +104,6 @@ msgstr "Email"
|
|||
|
||||
msgid "Verified label"
|
||||
msgstr "Email verified"
|
||||
|
||||
msgid "Account removed"
|
||||
msgstr "Account removed."
|
||||
|
|
|
@ -104,3 +104,6 @@ msgstr "Электронный адрес"
|
|||
|
||||
msgid "Verified label"
|
||||
msgstr "Адрес проверен"
|
||||
|
||||
msgid "Account removed"
|
||||
msgstr "Аккаунт удален."
|
||||
|
|
Loading…
Add table
Reference in a new issue