diff --git a/ShadowEditor.Model/System/ConfigModel.cs b/ShadowEditor.Model/System/ConfigModel.cs
index f708ffe3..60c1d967 100644
--- a/ShadowEditor.Model/System/ConfigModel.cs
+++ b/ShadowEditor.Model/System/ConfigModel.cs
@@ -15,5 +15,10 @@ namespace ShadowEditor.Model.System
/// ID
///
public string ID { get; set; }
+
+ ///
+ /// 默认注册用户ID
+ ///
+ public string DefaultRegisterRole { get; set; }
}
}
diff --git a/ShadowEditor.Server/Controllers/System/ConfigController.cs b/ShadowEditor.Server/Controllers/System/ConfigController.cs
index 16e32dc5..2f2a7434 100644
--- a/ShadowEditor.Server/Controllers/System/ConfigController.cs
+++ b/ShadowEditor.Server/Controllers/System/ConfigController.cs
@@ -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,
});
}
+
+ ///
+ /// 保存系统设置
+ ///
+ ///
+ ///
+ [HttpPost]
+ public JsonResult Save(ConfigModel model)
+ {
+ var mongo = new MongoHelper();
+
+ var filter = Builders.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.Update.Set("DefaultRegisterRole", model.DefaultRegisterRole);
+ mongo.UpdateOne(Constant.ConfigCollectionName, filter, update);
+ }
+
+ return Json(new
+ {
+ Code = 200,
+ Msg = "Save Successfully.",
+ Data = model,
+ });
+ }
}
}
diff --git a/ShadowEditor.Server/Controllers/System/InitializeController.cs b/ShadowEditor.Server/Controllers/System/InitializeController.cs
index 47e27bd7..8cff7f31 100644
--- a/ShadowEditor.Server/Controllers/System/InitializeController.cs
+++ b/ShadowEditor.Server/Controllers/System/InitializeController.cs
@@ -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.Filter.Eq("_id", doc["_id"].AsObjectId);
var update11 = Builders.Update.Set("Initialized", true);
- mongo.UpdateOne(Constant.ConfigCollectionName, filter11, update11);
+ var update12 = Builders.Update.Set("DefaultRegisterRole", defaultRegisterRoleID);
+ var update13 = Builders.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,
diff --git a/ShadowEditor.Web/locales/zh-CN.json b/ShadowEditor.Web/locales/zh-CN.json
index f5d8a66a..e9e272f6 100644
--- a/ShadowEditor.Web/locales/zh-CN.json
+++ b/ShadowEditor.Web/locales/zh-CN.json
@@ -886,5 +886,7 @@
"Pleast select a department.": "请选择机构。",
"Delete this department?": "删除这个机构?",
"PDept Name": "父机构名称",
- "Not allowed.": "不允许。"
+ "Not allowed.": "不允许。",
+ "System Setting": "系统设置",
+ "Register Default Role": "注册默认角色"
}
\ No newline at end of file
diff --git a/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx b/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx
index 6e5afd36..dc9a0b44 100644
--- a/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx
+++ b/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx
@@ -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 ;
}
@@ -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'),
diff --git a/ShadowEditor.Web/src/editor/system/LoginWindow.jsx b/ShadowEditor.Web/src/editor/system/LoginWindow.jsx
index 28ba7919..73d5df31 100644
--- a/ShadowEditor.Web/src/editor/system/LoginWindow.jsx
+++ b/ShadowEditor.Web/src/editor/system/LoginWindow.jsx
@@ -29,17 +29,26 @@ class LoginWindow extends React.Component {
style={{ width: '320px', height: '200px' }}
mask={false}
onClose={this.handleClose}
- >
+ >
diff --git a/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx b/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx
new file mode 100644
index 00000000..fd31c825
--- /dev/null
+++ b/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx
@@ -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
+
+
+
+
+
+
+
+ ;
+ }
+
+ 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;
\ No newline at end of file
diff --git a/ShadowEditor.Web/src/editor/system/css/SystemSettingWindow.css b/ShadowEditor.Web/src/editor/system/css/SystemSettingWindow.css
new file mode 100644
index 00000000..4552a5c0
--- /dev/null
+++ b/ShadowEditor.Web/src/editor/system/css/SystemSettingWindow.css
@@ -0,0 +1,3 @@
+.Window.SystemSettingWindow>.wrap>.content>.Form>.FormControl>.Label{
+ width: 100px;
+}
\ No newline at end of file