增加登录页面

main
落雨楓 8 months ago
parent ba6902aefe
commit 8ed8f865b1

@ -67,6 +67,9 @@
"JobClasses": {
"isekaiAIUpdateTitleIndex": "Isekai\\AIToolbox\\Job\\UpdateTitleIndexJob"
},
"SpecialPages": {
"IsekaiAIToolbox": "Isekai\\AIToolbox\\Special\\SpecialAIToolbox"
},
"ResourceModules": {
"ext.isekai.ai-toolbox.launcher": {
"scripts": [

@ -5,6 +5,11 @@
"isekai-ai-toolbox-menubutton": "启动AI工具箱",
"isekai-ai-toolbox-loading": "正在加载AI工具箱",
"isekaiaitoolbox": "AI工具箱",
"special-isekai-ai-toolbox": "AI工具箱",
"isekai-ai-toolbox-enter-toolbox": "进入AI工具箱",
"isekai-ai-toolbox-label-continue-curaccount": "你要以此帐号继续吗?",
"action-chatcomplete": "使用 Chat Complete 功能",
"right-chatcomplete": "使用 Chat Complete 功能",

@ -36,12 +36,19 @@ class ApiCreateToken extends ApiBase {
$result = $this->getResult();
$permissionMap = ApiAIToolbox::$permissionMap;
if (!$user->isAllowedAny(...array_values($permissionMap))) {
$this->addError('apierror-isekai-ai-toolbox-nopermission', 'nopermission');
return false;
$permissions = [];
foreach ($permissionMap as $key => $permissionKey) {
if ($user->isAllowed($permissionKey)) {
$permissions[] = $key;
}
}
// if (!$user->isAllowedAny(...array_values($permissionMap))) {
// $this->addError('apierror-isekai-ai-toolbox-nopermission', 'nopermission');
// return false;
// }
// Create JWT
$tokenId = $this->config->get('IsekaiAIToolboxTokenId');
$token = $this->config->get('IsekaiAIToolboxToken');
@ -55,6 +62,7 @@ class ApiCreateToken extends ApiBase {
'userName' => $user->getName(),
'iat' => $currentTime,
'exp' => $expireTime,
'permissions' => $permissions,
];
$jwt = JWT::encode($payload, $token, 'HS256', $tokenId);

@ -0,0 +1,70 @@
<?php
namespace Isekai\AIToolbox\Special;
use SpecialPage;
class SpecialAIToolbox extends SpecialPage {
public function __construct() {
parent::__construct('IsekaiAIToolbox', 'edit');
}
public function execute($subPage) {
$this->setHeaders();
$this->outputHeader();
$this->showForm();
}
protected function showForm() {
$user = $this->getUser();
$out = $this->getOutput();
$out->setPageTitle($this->msg('special-isekai-ai-toolbox'));
$out->addModuleStyles([
'mediawiki.special',
'mediawiki.interface.helpers.styles',
]);
$out->addModules([
'mediawiki.misc-authed-ooui',
'ext.isekai.ai-toolbox.launcher',
]);
$out->enableOOUI();
$fields = [];
$fields[] = new \OOUI\FieldLayout(
new \OOUI\LabelWidget([
'label' => $this->msg('isekai-ai-toolbox-label-continue-curaccount')->text(),
'align' => 'top',
])
);
$fields[] = new \OOUI\FieldLayout(
new \OOUI\ButtonWidget( [
'id' => 'btn-enter-ai-toolbox',
'label' => $this->msg('ok')->text(),
'flags' => ['primary', 'progressive'],
'type' => 'button',
]),
[
'align' => 'top',
]
);
$fieldset = new \OOUI\FieldsetLayout( [
'label' => $this->msg('isekai-ai-toolbox-enter-toolbox')->text(),
'id' => 'mw-aitoolbox-table',
'items' => $fields,
] );
$out->addHTML(
new \OOUI\PanelLayout([
'classes' => ['movepage-wrapper', 'aitoolbox-wrapper'],
'expanded' => false,
'padded' => true,
'framed' => true,
'content' => $fieldset,
])
);
}
}

@ -58,4 +58,10 @@ $(function() {
}
});
}
if ($('#btn-enter-ai-toolbox').length > 0) {
$('#btn-enter-ai-toolbox').on('click', function() {
launchAIToolbox();
});
}
});
Loading…
Cancel
Save