From e1283b013bcf858633f64f669bfee103263240d8 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Fri, 29 Sep 2023 20:39:41 +0800 Subject: [PATCH] feat(admin): basic settings --- js/dist/admin.js | Bin 3039 -> 6118 bytes js/dist/admin.js.map | Bin 10790 -> 18886 bytes js/src/admin/pages/IndexPage.js | 133 ++++++++++++++++++++++++++++++-- locale/zh-Hans.yml | 5 ++ 4 files changed, 132 insertions(+), 6 deletions(-) diff --git a/js/dist/admin.js b/js/dist/admin.js index cd03f944be6ca328ef2063c861793e5120b558b0..8d4d494d86c29a55cfedc5a27bf4773966de85d4 100644 GIT binary patch literal 6118 zcmc&&QFG(A5q|HlpwSr(I0w;p?X(Y6nVaO2Odpz_r%s+c8Vy9QM8qJV5};*Or~lps zKuDA=If`?+yx1fK>;m8Je)|EGro~s=2i_*O*s2`*7gfM$1leo`<_BGM65hLUkX5kY zowT`so3voNRwXv8sA5~5t6j>}j#W7Yrkve{ZmF}a6QL57+Dzj>osLFV?h*Xs$NA4t zq6t_C1vjl;L2EbeH?{@UHPG_8g#79)TY}Biou2N}9n(3r4A4bCd(~>I?Pdj8&CSQP zigvP+OX-KQHn+GU(y8F7B3Ff*pcl#QrkQIw8ioIv)wi}4YWX8yjz*_fXW8?y3{jLF z&q6w*nlm9dE`7LvDJla;y! z{L`$sy(9R)(dwG7R%D9f6;&xsGogePT#EleYcgI{lq|Hl-!#|3#8~sr*5eYCg_bb7 z=u~NiRy5r@Us^&Y^^%gi^RuSOKS4^(5{!1&BwSSquNtAQNV-eolJ&_Y`*Hn>U7nc2 zty`y)xQvAR;BEU%<3$gt0gE9HA^*5|fAVWK7pkIZ9&H_2vY6XGX=bwmnBB49Xcq@3 zZ5VE|eQHJDWeeN_g~Kl?8w|sEV2s+Xw7M;9v>O5^UO>TxQ7eptx&H3af-)F|8@>b# zrh}&R(1?g#h1G=?z84^?Td@5)DsN>K ztt?Mk3Axc(AjN?>8H>9^bKa(`AQnVcncCq z3g?D6-oNB+IBh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2edPvpvk)1fIi5!5rn3FgZohPv zORu>xnQ^fi`auA;o1vws8sH3sda>fL2b2UQWExJkAh>+#S(UQj1gbvwwkBr`+9*;Q`TlHm|s_Sb>cqdG~z zJa_Ao)VL8)4&34ai;uf0wtX5Ij+k87+TfPSeyafvHC4x0f=2~U9g-^@Y*CMn9LH<= z7)@h*a-f0c$JlhYjY2r{2$d5Q-qbmPb@XO0asxg!9^f~w;;-BSzgL$AEtvP?Bi)85 zZ>yFDOl>o>X`;p2Wt|g#@P9_J?6u7<-KJTZE@-xXwb^B9cIN+VUE8AnSBv!2)Pnvir(&zd9BFF+`l7j^bT5n_x=&c}! zM|5E`csx9QG5GP|Ys0ojd*om$h8_=neYN^%Al#VJC eZ0{em%qx3#NT0OZ^_uC}vxDtssn#+d?4>`!Z*E=y diff --git a/js/src/admin/pages/IndexPage.js b/js/src/admin/pages/IndexPage.js index b2dd824..241bc2d 100644 --- a/js/src/admin/pages/IndexPage.js +++ b/js/src/admin/pages/IndexPage.js @@ -1,11 +1,132 @@ +import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; +import FieldSet from 'flarum/common/components/FieldSet'; +import Button from 'flarum/common/components/Button'; +import saveSettings from 'flarum/admin/utils/saveSettings'; +import Stream from 'flarum/common/utils/Stream'; +import Select from 'flarum/common/components/Select'; +import Switch from 'flarum/common/components/Switch'; export default class IndexPage extends Page { - view() { - return ( -
-

Index Page

-
- ); + oninit(vnode) { + super.oninit(vnode); + + this.saving = false; + + this.fields = [ + 'foskym-oauth-center.access_lifetime', + 'foskym-oauth-center.allow_implicit', + 'foskym-oauth-center.enforce_state', + 'foskym-oauth-center.require_exact_redirect_uri' + ]; + this.values = {}; + + const settings = app.data.settings; + this.fields.forEach(key => this.values[key] = Stream(settings[key] || "")); + + for (let i = 1; i < this.fields.length; i++) { + this.values[this.fields[i]] = settings[this.fields[i]] === '1'; } + } + + view() { + return ( +
+
+ {FieldSet.component({}, [ +
, + Switch.component({ + state: this.values['foskym-oauth-center.allow_implicit'], + onchange: (value) => this.saveSingleSetting('foskym-oauth-center.allow_implicit', value), + loading: this.saving, + }, app.translator.trans('foskym-oauth-center.admin.settings.allow_implicit')), + ])} + + {FieldSet.component({}, [ +
, + Switch.component({ + state: this.values['foskym-oauth-center.enforce_state'], + onchange: (value) => this.saveSingleSetting('foskym-oauth-center.enforce_state', value), + loading: this.saving, + }, app.translator.trans('foskym-oauth-center.admin.settings.enforce_state')), + ])} + + {FieldSet.component({}, [ +
, + Switch.component({ + state: this.values['foskym-oauth-center.require_exact_redirect_uri'], + onchange: (value) => this.saveSingleSetting('foskym-oauth-center.require_exact_redirect_uri', value), + loading: this.saving, + }, app.translator.trans('foskym-oauth-center.admin.settings.require_exact_redirect_uri')), + ])} +
+ {FieldSet.component({}, [ + , +
+ {app.translator.trans('foskym-oauth-center.admin.settings.access_lifetime')} +
, + Button.component({ + type: 'submit', + className: 'Button Button--primary', + loading: this.saving + }, app.translator.trans('core.admin.settings.submit_button')) + ])} + +
+ +
+ ); + } + + saveSingleSetting(setting, value) { + if (this.saving) return; + + this.saving = true; + + this.values[setting] = value; + + let data = {}; + data[setting] = value; + + saveSettings(data) + .then(() => app.alerts.show({type: 'success'}, app.translator.trans('core.admin.settings.saved_message'))) + .catch(() => { + }) + .then(() => { + this.saving = false; + m.redraw(); + }); + } + + onsubmit(e) { + e.preventDefault(); + + if (this.saving) return; + + this.saving = true; + app.alerts.dismiss(this.successAlert); + + const settings = {}; + + settings['foskym-oauth-center.access_lifetime'] = this.values['foskym-oauth-center.access_lifetime'](); + + // this.fields.forEach(key => { + // settings[key] = this.values[key]() + // + // }); + + if (settings['foskym-oauth-center.access_lifetime'] === "") { + settings['foskym-oauth-center.access_lifetime'] = 3600; + } + + saveSettings(settings) + .then(() => app.alerts.show({type: 'success'}, app.translator.trans('core.admin.settings.saved_message'))) + .catch(() => { + }) + .then(() => { + this.saving = false; + m.redraw(); + }); + } } diff --git a/locale/zh-Hans.yml b/locale/zh-Hans.yml index 8538f05..bcf5ca1 100644 --- a/locale/zh-Hans.yml +++ b/locale/zh-Hans.yml @@ -4,6 +4,11 @@ foskym-oauth-center: index: 首页 clients: 应用管理 scopes: 权限管理 + settings: + access_lifetime: 访问令牌有效期(秒) + allow_implicit: 允许隐式授权(response_type=token) + enforce_state: 强制状态验证(state 参数) + require_exact_redirect_uri: 需要精确的重定向 URI forum: page: