OAuth (part 7 draft)
This commit is contained in:
parent
f5aa9c8d57
commit
266c00c210
11 changed files with 216 additions and 5 deletions
|
@ -214,19 +214,19 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[1-9]\d*}/edit/email',
|
||||
'/user/{id|i:[1-9]\d*}/edit/profile/email',
|
||||
'ProfileEmail:email',
|
||||
'EditUserEmail'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[1-9]\d*}/edit/passphrase',
|
||||
'/user/{id|i:[1-9]\d*}/edit/profile/passphrase',
|
||||
'ProfilePass:pass',
|
||||
'EditUserPass'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[1-9]\d*}/edit/moderation',
|
||||
'/user/{id|i:[1-9]\d*}/edit/profile/moderation',
|
||||
'ProfileMod:moderation',
|
||||
'EditUserModeration'
|
||||
);
|
||||
|
@ -252,17 +252,35 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:' . $user->id . '}/edit/email',
|
||||
'/user/{id|i:' . $user->id . '}/edit/profile/email',
|
||||
'ProfileEmail:email',
|
||||
'EditUserEmail'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:' . $user->id . '}/edit/passphrase',
|
||||
'/user/{id|i:' . $user->id . '}/edit/profile/passphrase',
|
||||
'ProfilePass:pass',
|
||||
'EditUserPass'
|
||||
);
|
||||
}
|
||||
// управление аккаунтами OAuth
|
||||
if (
|
||||
! $user->isGuest
|
||||
&& 1 === $config->b_oauth_allow
|
||||
) {
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/user/{id|i:' . $user->id . '}/edit/profile/oauth',
|
||||
'ProfileOAuth:list',
|
||||
'EditUserOAuth'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:' . $user->id . '}/edit/profile/oauth/{key}',
|
||||
'ProfileOAuth:action',
|
||||
'EditUserOAuthAction'
|
||||
);
|
||||
}
|
||||
// смена своего email
|
||||
if (! $user->isGuest) {
|
||||
$r->add(
|
||||
|
|
|
@ -509,4 +509,22 @@ class Update extends Admin
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* rev.55 to rev.56
|
||||
*/
|
||||
protected function stageNumber55(array $args): ?int
|
||||
{
|
||||
$coreConfig = new CoreConfig($this->configFile);
|
||||
|
||||
$coreConfig->add(
|
||||
'multiple=>ProfileOAuth',
|
||||
'\\ForkBB\\Models\\Pages\\Profile\\OAuth::class',
|
||||
'ProfileMod'
|
||||
);
|
||||
|
||||
$coreConfig->save();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,6 +296,13 @@ class Edit extends Profile
|
|||
'href' => $this->c->Router->link('EditUserPass', $args),
|
||||
];
|
||||
}
|
||||
if ($this->rules->configureOAuth) {
|
||||
$fields['configure_oauth'] = [
|
||||
'type' => 'link',
|
||||
'value' => __('Configure OAuth'),
|
||||
'href' => $this->c->Router->link('EditUserOAuth', $args),
|
||||
];
|
||||
}
|
||||
if ($this->rules->useAvatar) {
|
||||
if (! $this->curUser->avatar) {
|
||||
$fields['avatar'] = [
|
||||
|
|
100
app/Models/Pages/Profile/OAuth.php
Normal file
100
app/Models/Pages/Profile/OAuth.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the ForkBB <https://github.com/forkbb>.
|
||||
*
|
||||
* @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
|
||||
* @license The MIT License (MIT)
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
use RegLogTrait;
|
||||
|
||||
/**
|
||||
* Подготавливает данные для шаблона списка аккаунтов
|
||||
*/
|
||||
public function list(array $args, string $method): Page
|
||||
{
|
||||
if (
|
||||
false === $this->initProfile($args['id'])
|
||||
|| ! $this->rules->configureOAuth
|
||||
) {
|
||||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
|
||||
$this->c->Lang->load('admin_providers');
|
||||
|
||||
$this->crumbs = $this->crumbs(
|
||||
[
|
||||
$this->c->Router->link('EditUserOAuth', $args),
|
||||
'OAuth accounts',
|
||||
],
|
||||
[
|
||||
$this->c->Router->link('EditUserProfile', $args),
|
||||
'Editing profile',
|
||||
]
|
||||
);
|
||||
$this->form = $this->formList($args);
|
||||
$this->formOAuth = $this->reglogForm();
|
||||
$this->actionBtns = $this->btns('edit');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создает массив данных для формы аккаунтов
|
||||
*/
|
||||
protected function formList(array $args): array
|
||||
{
|
||||
$data = $this->c->providerUser->loadUserData($this->curUser);
|
||||
|
||||
if (0 === \count($data)) {
|
||||
$this->fIswev = ['i', 'No linked accounts'];
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
|
||||
foreach ($data as $cur) {
|
||||
$key = $cur['name'] . '-' . $cur['userId'];
|
||||
$args['key'] = $key;
|
||||
$value = __($cur['name']);
|
||||
$title = $value . " ({$cur['userId']})";
|
||||
$fields[$key] = [
|
||||
'type' => 'btn',
|
||||
'class' => ['oauth-acc-btn'],
|
||||
'value' => $value,
|
||||
'title' => $title,
|
||||
'link' => $this->c->Router->link('EditUserOAuthAction', $args),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'action' => null,
|
||||
'sets' => [
|
||||
'oauth-accounts' => [
|
||||
'class' => ['account-links'],
|
||||
'legend' => 'Linked accounts',
|
||||
'fields' => $fields,
|
||||
],
|
||||
],
|
||||
'btns' => null,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -130,6 +130,21 @@ class ProviderUser extends Model
|
|||
WHERE uid IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Вовращает список записей по пользователю
|
||||
*/
|
||||
public function loadUserData(User $user): array
|
||||
{
|
||||
$vars = [
|
||||
':id' => $user->id,
|
||||
];
|
||||
$query = 'SELECT pu.pr_name AS name, pu.pu_uid AS userId, pu.pu_email AS userEmail, pu.pu_email_verified AS userEmailVerifed
|
||||
FROM ::providers_users AS pu
|
||||
WHERE pu.uid=?i:id
|
||||
ORDER BY pu.pr_name, pu.pu_uid';
|
||||
|
||||
return $this->c->DB->query($query, $vars)->fetchAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,4 +185,9 @@ class Profile extends Rules
|
|||
|| 1 === $this->c->config->b_topic_subscriptions
|
||||
);
|
||||
}
|
||||
|
||||
protected function getconfigureOAuth(): bool
|
||||
{
|
||||
return $this->my && 1 === $this->c->config->b_oauth_allow;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -365,6 +365,7 @@ return [
|
|||
'ProfilePass' => \ForkBB\Models\Pages\Profile\Pass::class,
|
||||
'ProfileEmail' => \ForkBB\Models\Pages\Profile\Email::class,
|
||||
'ProfileMod' => \ForkBB\Models\Pages\Profile\Mod::class,
|
||||
'ProfileOAuth' => \ForkBB\Models\Pages\Profile\OAuth::class,
|
||||
'AdminIndex' => \ForkBB\Models\Pages\Admin\Index::class,
|
||||
'AdminStatistics' => \ForkBB\Models\Pages\Admin\Statistics::class,
|
||||
'AdminOptions' => \ForkBB\Models\Pages\Admin\Options::class,
|
||||
|
|
|
@ -317,3 +317,18 @@ msgstr "Show user subscriptions to topics"
|
|||
|
||||
msgid "Show forums subscriptions"
|
||||
msgstr "Show user subscriptions to forums"
|
||||
|
||||
msgid "Configure OAuth"
|
||||
msgstr "Configure OAuth accounts"
|
||||
|
||||
msgid "OAuth accounts"
|
||||
msgstr "OAuth accounts"
|
||||
|
||||
msgid "No linked accounts"
|
||||
msgstr "No linked accounts."
|
||||
|
||||
msgid "Linked accounts"
|
||||
msgstr "Linked accounts"
|
||||
|
||||
msgid "Add account"
|
||||
msgstr "Add new account"
|
||||
|
|
|
@ -317,3 +317,18 @@ msgstr "Показать подписки пользователя на темы
|
|||
|
||||
msgid "Show forums subscriptions"
|
||||
msgstr "Показать подписки пользователя на разделы"
|
||||
|
||||
msgid "Configure OAuth"
|
||||
msgstr "Настроить аккаунты OAuth"
|
||||
|
||||
msgid "OAuth accounts"
|
||||
msgstr "Аккаунты OAuth"
|
||||
|
||||
msgid "No linked accounts"
|
||||
msgstr "Нет связанных аккаунтов."
|
||||
|
||||
msgid "Linked accounts"
|
||||
msgstr "Связанные аккаунты"
|
||||
|
||||
msgid "Add account"
|
||||
msgstr "Привязать новый аккаунт"
|
||||
|
|
|
@ -26,3 +26,11 @@
|
|||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if ($form = $p->formOAuth)
|
||||
<div id="fork-oauth" class="f-main">
|
||||
<div class="f-fdiv f-lrdiv">
|
||||
<h2>{!! __('Add account') !!}</h2>
|
||||
@include ('layouts/form')
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
|
|
@ -2488,6 +2488,15 @@ body,
|
|||
padding: 0 0.25rem;
|
||||
}
|
||||
|
||||
#fork #id-fs-oauth-accounts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
#fork .f-field-oauth-acc-btn {
|
||||
flex: 1 0 17rem;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 40rem) {
|
||||
#fork .f-fs-header .f-wrap-usertitle {
|
||||
order: 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue