修改默认注册用户。

This commit is contained in:
tengge1 2019-10-27 14:39:22 +08:00
parent 42b47163b1
commit 064fcbf6cf
8 changed files with 221 additions and 17 deletions

View File

@ -15,5 +15,10 @@ namespace ShadowEditor.Model.System
/// ID
/// </summary>
public string ID { get; set; }
/// <summary>
/// 默认注册用户ID
/// </summary>
public string DefaultRegisterRole { get; set; }
}
}

View File

@ -43,7 +43,8 @@ namespace ShadowEditor.Server.Controllers.System
config = new BsonDocument
{
["ID"] = ObjectId.GenerateNewId(),
["Initialized"] = false
["Initialized"] = false,
["DefaultRegisterRole"] = ""
};
mongo.InsertOne(Constant.ConfigCollectionName, config);
}
@ -53,6 +54,7 @@ namespace ShadowEditor.Server.Controllers.System
["ID"] = config["ID"].ToString(),
["EnableAuthority"] = ConfigurationManager.AppSettings["EnableAuthority"] == "true",
["Initialized"] = config.Contains("Initialized") ? config["Initialized"].ToBoolean() : false,
["DefaultRegisterRole"] = config.Contains("DefaultRegisterRole") ? config["DefaultRegisterRole"].ToString() : "",
["IsLogin"] = false,
["Username"] = "",
["Name"] = "",
@ -100,5 +102,44 @@ namespace ShadowEditor.Server.Controllers.System
Data = model,
});
}
/// <summary>
/// 保存系统设置
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public JsonResult Save(ConfigModel model)
{
var mongo = new MongoHelper();
var filter = Builders<BsonDocument>.Filter.Empty;
// 获取配置
var doc = mongo.FindOne(Constant.ConfigCollectionName, filter);
if (doc == null)
{
doc = new BsonDocument
{
["ID"] = ObjectId.GenerateNewId(),
["Initialized"] = false,
["DefaultRegisterRole"] = model.DefaultRegisterRole
};
mongo.InsertOne(Constant.ConfigCollectionName, doc);
}
else
{
var update = Builders<BsonDocument>.Update.Set("DefaultRegisterRole", model.DefaultRegisterRole);
mongo.UpdateOne(Constant.ConfigCollectionName, filter, update);
}
return Json(new
{
Code = 200,
Msg = "Save Successfully.",
Data = model,
});
}
}
}

View File

@ -56,12 +56,15 @@ namespace ShadowEditor.Server.Controllers.System
});
}
var defaultRegisterRoleID = ObjectId.GenerateNewId();
if (doc == null)
{
doc = new BsonDocument
{
["ID"] = ObjectId.GenerateNewId(),
["Initialized"] = true
["Initialized"] = true,
["DefaultRegisterRole"] = defaultRegisterRoleID
};
mongo.InsertOne(Constant.ConfigCollectionName, doc);
}
@ -69,7 +72,9 @@ namespace ShadowEditor.Server.Controllers.System
{
var filter11 = Builders<BsonDocument>.Filter.Eq("_id", doc["_id"].AsObjectId);
var update11 = Builders<BsonDocument>.Update.Set("Initialized", true);
mongo.UpdateOne(Constant.ConfigCollectionName, filter11, update11);
var update12 = Builders<BsonDocument>.Update.Set("DefaultRegisterRole", defaultRegisterRoleID);
var update13 = Builders<BsonDocument>.Update.Combine(update11, update12);
mongo.UpdateOne(Constant.ConfigCollectionName, filter11, update13);
}
// 初始化角色
@ -95,7 +100,7 @@ namespace ShadowEditor.Server.Controllers.System
var role2 = new BsonDocument
{
["ID"] = ObjectId.GenerateNewId(),
["ID"] = defaultRegisterRoleID,
["Name"] = "User",
["CreateTime"] = now,
["UpdateTime"] = now,

View File

@ -886,5 +886,7 @@
"Pleast select a department.": "请选择机构。",
"Delete this department?": "删除这个机构?",
"PDept Name": "父机构名称",
"Not allowed.": "不允许。"
"Not allowed.": "不允许。",
"System Setting": "系统设置",
"Register Default Role": "注册默认角色"
}

View File

@ -1,8 +1,9 @@
import { classNames, PropTypes, MenuBar, MenuItem, MenuItemSeparator } from '../../third_party';
import { MenuItem, MenuItemSeparator } from '../../third_party';
import DepartmentManagementWindow from '../system/DepartmentManagementWindow.jsx';
import UserManageWindow from '../system/UserManageWindow.jsx';
import RoleManageWindow from '../system/RoleManageWindow.jsx';
import AuthorityManagementWindow from '../system/AuthorityManagementWindow.jsx';
import SystemSettingWindow from '../system/SystemSettingWindow.jsx';
/**
* 系统菜单
@ -18,23 +19,46 @@ class SystemMenu extends React.Component {
this.handleUser = this.handleUser.bind(this);
this.handleRole = this.handleRole.bind(this);
this.handleAuthority = this.handleAuthority.bind(this);
this.handleSystemSetting = this.handleSystemSetting.bind(this);
this.handleResetSystem = this.handleResetSystem.bind(this);
this.commitResetSystem = this.commitResetSystem.bind(this);
}
render() {
const { enableAuthority, initialized, login } = app.config;
const { initialized } = app.config;
return <MenuItem title={_t('System')}>
<MenuItem title={_t('Initialize')} show={!initialized} onClick={this.handleInitialize} />
<MenuItem title={_t('Initialize')}
show={!initialized}
onClick={this.handleInitialize}
/>
<MenuItemSeparator show={initialized} />
<MenuItem title={_t('Department Management')} show={initialized} onClick={this.handleDepartment} />
<MenuItem title={_t('User Management')} show={initialized} onClick={this.handleUser} />
<MenuItem title={_t('Department Management')}
show={initialized}
onClick={this.handleDepartment}
/>
<MenuItem title={_t('User Management')}
show={initialized}
onClick={this.handleUser}
/>
<MenuItemSeparator show={initialized} />
<MenuItem title={_t('Role Management')} show={initialized} onClick={this.handleRole} />
<MenuItem title={_t('Authority Management')} show={initialized} onClick={this.handleAuthority} />
<MenuItem title={_t('Role Management')}
show={initialized}
onClick={this.handleRole}
/>
<MenuItem title={_t('Authority Management')}
show={initialized}
onClick={this.handleAuthority}
/>
<MenuItemSeparator show={initialized} />
<MenuItem title={_t('Reset System')} show={initialized} onClick={this.handleResetSystem} />
<MenuItem title={_t('System Setting')}
show={initialized}
onClick={this.handleSystemSetting}
/>
<MenuItem title={_t('Reset System')}
show={initialized}
onClick={this.handleResetSystem}
/>
</MenuItem>;
}
@ -86,6 +110,11 @@ class SystemMenu extends React.Component {
app.addElement(win);
}
handleSystemSetting() {
const win = app.createElement(SystemSettingWindow);
app.addElement(win);
}
handleResetSystem() {
app.confirm({
title: _t('Query'),

View File

@ -29,17 +29,26 @@ class LoginWindow extends React.Component {
style={{ width: '320px', height: '200px' }}
mask={false}
onClose={this.handleClose}
>
>
<Content>
<Form>
<FormControl>
<Label>{_t('Username')}</Label>
<Input name={'username'} value={username} onChange={this.handleChange} />
<input type={'password'} className={'fake'} />
<Input name={'username'}
value={username}
onChange={this.handleChange}
/>
<input type={'password'}
className={'fake'}
/>
</FormControl>
<FormControl>
<Label>{_t('Password')}</Label>
<Input name={'password'} type={'password'} value={password} onChange={this.handleChange} />
<Input name={'password'}
type={'password'}
value={password}
onChange={this.handleChange}
/>
</FormControl>
</Form>
</Content>

View File

@ -0,0 +1,110 @@
import './css/SystemSettingWindow.css';
import { Window, Content, Buttons, Form, FormControl, Label, Button, Select } from '../../third_party';
/**
* 系统设置窗口
* @author tengge / https://github.com/tengge1
*/
class SystemSettingWindow extends React.Component {
constructor(props) {
super(props);
this.state = {
roles: {},
registerRole: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSave = this.handleSave.bind(this);
this.handleClose = this.handleClose.bind(this);
}
render() {
const { roles, registerRole } = this.state;
return <Window
className={'SystemSettingWindow'}
title={_t('System Setting')}
style={{ width: '320px', height: '200px' }}
mask={false}
onClose={this.handleClose}
>
<Content>
<Form>
<FormControl>
<Label>{_t('Register Default Role')}</Label>
<Select name={'registerRole'}
options={roles}
value={registerRole}
onChange={this.handleChange}
/>
</FormControl>
</Form>
</Content>
<Buttons>
<Button onClick={this.handleSave}>{_t('OK')}</Button>
<Button onClick={this.handleClose}>{_t('Cancel')}</Button>
</Buttons>
</Window>;
}
componentDidMount() {
fetch(`/api/Config/Get`).then(response => {
response.json().then(json => {
this.setState({
registerRole: json.Data.DefaultRegisterRole
});
});
});
fetch(`/api/Role/List?pageSize=10000`).then(response => {
response.json().then(json => {
let roles = {};
json.Data.rows.forEach(n => {
roles[n.ID] = this.renderRoleName(n.Name);
});
this.setState({
roles
});
});
});
}
handleChange(value, name) {
this.setState({
[name]: value
});
}
handleSave() {
const { registerRole } = this.state;
fetch(`/api/Config/Save`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `DefaultRegisterRole=${registerRole}`
}).then(response => {
response.json().then(json => {
app.toast(_t(json.Msg));
this.handleClose();
});
});
}
handleClose() {
app.removeElement(this);
}
renderRoleName(value) {
if (value === 'Administrator' ||
value === 'User' ||
value === 'Guest') {
return _t(value);
}
return value;
}
}
export default SystemSettingWindow;

View File

@ -0,0 +1,3 @@
.Window.SystemSettingWindow>.wrap>.content>.Form>.FormControl>.Label{
width: 100px;
}