feat(admin): basic settings
This commit is contained in:
parent
87fa72d4f7
commit
e1283b013b
4 changed files with 132 additions and 6 deletions
BIN
js/dist/admin.js
generated
vendored
BIN
js/dist/admin.js
generated
vendored
Binary file not shown.
BIN
js/dist/admin.js.map
generated
vendored
BIN
js/dist/admin.js.map
generated
vendored
Binary file not shown.
|
@ -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 {
|
||||
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 (
|
||||
<div>
|
||||
<h2>Index Page</h2>
|
||||
<form onsubmit={this.onsubmit.bind(this)} className="BasicsPage">
|
||||
{FieldSet.component({}, [
|
||||
<div style="height: 5px;"></div>,
|
||||
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({}, [
|
||||
<div style="height: 5px;"></div>,
|
||||
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({}, [
|
||||
<div style="height: 5px;"></div>,
|
||||
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')),
|
||||
])}
|
||||
<hr/>
|
||||
{FieldSet.component({}, [
|
||||
<input className="FormControl" bidi={this.values['foskym-oauth-center.access_lifetime']}
|
||||
placeholder={app.translator.trans('foskym-oauth-center.admin.settings.access_lifetime')} required/>,
|
||||
<div className="helpText">
|
||||
{app.translator.trans('foskym-oauth-center.admin.settings.access_lifetime')}
|
||||
</div>,
|
||||
Button.component({
|
||||
type: 'submit',
|
||||
className: 'Button Button--primary',
|
||||
loading: this.saving
|
||||
}, app.translator.trans('core.admin.settings.submit_button'))
|
||||
])}
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue