feat(admin): clients page

This commit is contained in:
FoskyM 2023-09-30 09:55:35 +08:00
parent 54e7659d9f
commit 7777628c8d
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
6 changed files with 121 additions and 9 deletions

View file

@ -28,7 +28,7 @@ return [
(new Extend\Routes('forum'))
->post('/oauth/authorize', 'oauth.authorize.post', Controllers\AuthorizeController::class),
(new Extend\Routes('api'))
->get('/oauth/clients', 'oauth.clients.list', Api\Controller\ListClientController::class),
->get('/oauth-clients', 'oauth.clients.list', Api\Controller\ListClientController::class),
(new Extend\Middleware('api'))->add(ResourceScopeMiddleware::class),
];

BIN
js/dist/admin.js generated vendored

Binary file not shown.

BIN
js/dist/admin.js.map generated vendored

Binary file not shown.

View file

@ -1,22 +1,104 @@
import app from 'flarum/admin/app';
import Page from 'flarum/common/components/Page';
import AdminPage from 'flarum/admin/components/AdminPage';
import Button from 'flarum/common/components/Button';
import Client from "../../common/models/Client";
export default class ClientsPage extends Page {
settingName = 'collapsible-posts.reasons';
translationPrefix = 'foskym-oauth-center.admin.clients.';
clients = [];
oninit(vnode) {
super.oninit(vnode);
app.store.find('oauth/clients').then(() => {
this.fields = [
'client_id',
'client_secret',
'redirect_uri',
'grant_types',
'scope',
'client_name',
'client_desc',
'client_icon',
'client_home'
];
app.store.find('oauth-clients').then(r => {
this.clients = r;
this.fields.map(key => console.log(this.clients[0][key]))
m.redraw();
});
}
view() {
return (
<div>
<h2>Clients Page</h2>
<div class={"OAuthCenter-clientsPage"}>
{
m('.Form-group', [
m('table', [
m('thead', m('tr', [
this.fields.map(key => m('th', app.translator.trans(this.translationPrefix + key))),
m('th'),
])),
m('tbody', [
this.clients.map((client, index) => m('tr', [
this.fields.map(key =>
m('td', m('input.FormControl', {
type: 'text',
value: client[key]() || '',
onchange: (event) => {
this.saveClientInfo(client.id(), key, event.target.value);
},
}))
),
m('td', Button.component({
className: 'Button Button--icon',
icon: 'fas fa-times',
onclick: () => {
this.clients.splice(index, 1);
// this.setting(settingName)(JSON.stringify(reasons));
},
})),
])),
m('tr', m('td', {
colspan: 9,
}, Button.component({
className: 'Button Button--block',
onclick: () => {
const client = app.store.createRecord('oauth-clients');
client.save({
client_id: this.randomString(32),
client_secret: this.randomString(32),
}).then(console.log);
// this.clients.push(Client.build({
//
// }));
// this.setting(settingName)(JSON.stringify(reasons));
},
}, app.translator.trans(this.translationPrefix + 'add_button')))),
]),
]),
])
}
</div>
);
}
randomString(len) {
len = len || 32;
let $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let maxPos = $chars.length;
let pwd = '';
for (let i = 0; i < len; i++) {
//0~32的整数
pwd += $chars.charAt(Math.floor(Math.random() * (maxPos + 1)));
}
return pwd;
}
saveClientInfo(id, key, value) {
console.log(id, key, value);
}
}

View file

@ -24,6 +24,35 @@
}
}
}
.OAuthCenterPage-container {
max-width: 100% !important;
}
.OAuthCenter-clientsPage {
table {
width: 100%;
td, th {
padding: 3px 5px;
}
th {
text-align: left;
}
}
.FormControl {
background: @body-bg;
border-color: @control-bg;
// We set the same as Flarum default, but with more specificity
&:focus,
&.focus {
border-color: @primary-color;
}
}
}
}
@media (min-width: 992px) {
.OAuthCenter {

View file

@ -15,10 +15,11 @@ foskym-oauth-center:
redirect_uri: 回调地址(多地址请用空格分割)
grant_types: 授权类型(可空)
scope: 权限(可空)
name: 应用名称(可空)
description: 应用描述(可空)
icon: 应用图标地址(可空 可使用fontawesome图标
home: 主页地址(可空)
client_name: 应用名称(可空)
client_desc: 应用描述(可空)
client_icon: 应用图标地址(可空 可使用fontawesome图标
client_home: 主页地址(可空)
add_button: 添加应用
forum:
page: