From 7777628c8d22456a61af290aec7cbca46b14835c Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sat, 30 Sep 2023 09:55:35 +0800 Subject: [PATCH] feat(admin): clients page --- extend.php | 2 +- js/dist/admin.js | Bin 7015 -> 8327 bytes js/dist/admin.js.map | Bin 20632 -> 25169 bytes js/src/admin/pages/ClientsPage.js | 90 ++++++++++++++++++++++++++++-- less/admin.less | 29 ++++++++++ locale/zh-Hans.yml | 9 +-- 6 files changed, 121 insertions(+), 9 deletions(-) diff --git a/extend.php b/extend.php index c8f1edd..bad30c4 100644 --- a/extend.php +++ b/extend.php @@ -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), ]; diff --git a/js/dist/admin.js b/js/dist/admin.js index 47a216f0b03a994c05c3c66bcdb4dd3fc1aa9845..589a21ae64ba68aee1b50010ef57e7c5ecd50726 100644 GIT binary patch delta 1707 zcma)7OK%)S5Z2i1SB!9sABk;*)}sJD@p$3~7_#dj**L_6#19g}Yqc`%ncmqZGu=y1 z?_#rFZIF=Qf{4=MNW__30RI3ua^L_Lj$DzraDX2`&0`;d9N3jg)7>@IUw!pe&F^cU z6uvppcakD$5~CrAtO=H-wp!|&Qs??Ek0%Gsa*a8Xa+Ve9Eg(#WMXElZ zSXE#3pU^_}p#Ln`U;7uqW-<$4mojI--pXXb)-%t5{W25z{21H6V*Av<)1v|rQyL~| zqEKxQ{BhEYF}OxP0a{OiKB4&FxK=;@Xz(RXy9DqqXyUu!yV@+ZmjR%x(9kMV;=7^c z6XwZEo~o}$=4NQAWb4biZQH!q<5Z-_zm41((7fZlv7h?2y!vHucFy5Jm9r?fa|Jh` zY!`bZWk!8JH1~h__+rd*d>Vz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PaQtv7mV)shXpKXa=@MD7u;Wkga+tP%r$%hhj4>o33F!)Rxp4z zU;@D^oCdh+Yhg5jK80Jqir^6n0aqXdu7X=wAiHoQe&H^T@aLuGTQI&o~OoVgF83m0te$K07SXU;v}zc#&j*YxS6z2*Lf z#G{Vqt=6Oz35W#stB!mY0YD(#WKvjkp0vysMllbZXj2SLDCBMX5s`tyo+60#T{Xo) z+*e3f0!jlUxDpql`m=9%ByQ?K!~rsO6b^tR$`YU~A9BnQ%YZI!NnN-+TttgN(DDfI ziv^}J^#fZJCCo4J9j7D_HmobsJExU!P;E(v-!setN{VQBjG(9t4MVY{H24C#*Wd1+ z@j9JmQWDP}j%ewh36$}yN0LOKcIgFbVY@P}U;BrfH!S_d-?K92A@Ic1ilwS}D5qf4 ztksMPv)*^r9qFkxEvrhTxPoT1xh!s^P3)M>s-q5e^)~OIPIN`1H6^kD*(ix;2c?$+ zJc?tnFd4CnfJ-@}?WUI-BTRdP!7Ol@5JFw)A6~GdBEFafcIJSy4xUYn{ZOCbq?63DyeZE7S+w(HReO`(MoPIWharFzXU9 zmgI5bG`N*B@F_hNu$ybBp9VT_o{!{z0hj**{tAQ+c8y-fw%Hilc9Cbz(!anWdk;^) zge^zrSf*EuvFeK{eg*G0kj!Fy7YA#-V$N7H1!)=scgzuKzEjt-6O5%UWXV&pAZ{uB zzGu31TZvVG)!gyVo)12KIMjB0ap*?BK1}-bOH64seo6lxYtwJlGu^ly)G~6_Kat-k z7u-hu*64VnRB%T|MhEWA4Ls4`BDOvWw_PcP=FrO+NUjzOvlA51lXKUPUnHX)E$d}> eO@Caib#JbD=*2kunJY diff --git a/js/src/admin/pages/ClientsPage.js b/js/src/admin/pages/ClientsPage.js index fd464c3..594f0a1 100644 --- a/js/src/admin/pages/ClientsPage.js +++ b/js/src/admin/pages/ClientsPage.js @@ -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 ( -
-

Clients Page

+
+ { + 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')))), + ]), + ]), + ]) + }
); } + + 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); + } } diff --git a/less/admin.less b/less/admin.less index 9795d1f..29341b2 100644 --- a/less/admin.less +++ b/less/admin.less @@ -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 { diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index 7bcb0f0..8c7e4f2 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -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: