diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs
index 5741e836..b61bd518 100644
--- a/Bootstrap.Admin/Controllers/Api/UsersController.cs
+++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs
@@ -1,6 +1,5 @@
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
-using Bootstrap.Security;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -44,9 +43,9 @@ namespace Bootstrap.Admin.Controllers.Api
if (value.UserName.Equals(User.Identity.Name, System.StringComparison.OrdinalIgnoreCase))
{
if (value.UserStatus == UserStates.ChangeDisplayName)
- ret = BootstrapUser.SaveDisplayName(value.UserName, value.DisplayName);
+ ret = UserHelper.SaveDisplayName(value.UserName, value.DisplayName);
else if (value.UserStatus == UserStates.ChangePassword)
- ret = BootstrapUser.ChangePassword(value.UserName, value.Password, value.NewPassword);
+ ret = UserHelper.ChangePassword(value.UserName, value.Password, value.NewPassword);
}
return ret;
}
diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json
index 6ba22465..77aa4267 100644
--- a/Bootstrap.Admin/appsettings.json
+++ b/Bootstrap.Admin/appsettings.json
@@ -46,182 +46,196 @@
"Key": "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台菜单获得所有可访问角色数据缓存"
+ "Desc": "通过菜单获得所有角色数据"
},
{
"Enabled": true,
"Key": "BootstrapAdminGroupMiddleware-RetrieveGroups",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理所有组数据缓存"
+ "Desc": "所有组数据缓存"
},
{
"Enabled": true,
"Key": "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理特定用户所属所有组数据缓存"
+ "Desc": "指定用户所有组数据缓存"
},
{
"Enabled": true,
"Key": "BootstrapAdminRoleMiddleware-RetrieveRoles",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理所有角色数据缓存"
+ "Desc": "所有角色数据缓存"
},
{
"Enabled": true,
"Key": "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理特定用户所属所有角色数据缓存"
+ "Desc": "指定用户角色数据缓存"
},
{
"Enabled": true,
"Key": "BootstrapDict-RetrieveDicts",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理所有字典数据缓存"
+ "Desc": "所有字典数据缓存"
},
{
"Enabled": true,
- "Key": "BootstrapMenu-RetrieveMenus",
+ "Key": "BootstrapMenu-RetrieveMenusByUserName",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理所有菜单数据缓存"
+ "Desc": "用户所有菜单数据缓存"
},
{
"Enabled": true,
"Key": "BootstrapUser-RetrieveUsers",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理所有用户数据缓存"
+ "Desc": "所有用户数据"
},
{
"Enabled": true,
"Key": "BootstrapUser-RetrieveUsersByName",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "后台管理通过登录名获得当前用户数据缓存"
+ "Desc": "登录用户数据"
+ },
+ {
+ "Enabled": true,
+ "Key": "BootstrapUser-RetrieveUsersByRoleId",
+ "Interval": 600,
+ "SlidingExpiration": true,
+ "Desc": "通过角色ID获得所有用户数据"
+ },
+ {
+ "Enabled": true,
+ "Key": "BootstrapUser-RetrieveUsersByGroupId",
+ "Interval": 600,
+ "SlidingExpiration": true,
+ "Desc": "通过部门ID获得所有用户数据"
},
{
"Enabled": true,
"Key": "UserHelper-RetrieveNewUsers",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "新用户数据缓存"
+ "Desc": "新用户数据"
},
{
"Enabled": true,
"Key": "MenuHelper-RetrieveMenusByRoleId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "角色菜单信息缓存"
+ "Desc": "通过角色ID获得所有菜单数据"
},
{
"Enabled": true,
"Key": "RoleHelper-RetrieveRoles",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "所有角色数据缓存"
+ "Desc": "所有角色数据"
},
{
"Enabled": true,
"Key": "RoleHelper-RetrieveRolesByUserId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "指定用户角色数据缓存"
+ "Desc": "通过用户ID获得所有角色数据"
},
{
"Enabled": true,
"Key": "RoleHelper-RetrieveRolesByMenuId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "指定菜单角色数据缓存"
+ "Desc": "通过菜单ID获得所有角色数据"
},
{
"Enabled": true,
"Key": "RoleHelper-RetrieveRolesByGroupId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "指定组角色数据缓存"
+ "Desc": "通过部门ID获得所有角色数据"
},
{
"Enabled": true,
"Key": "GroupHelper-RetrieveGroups",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "所有组数据缓存"
+ "Desc": "所有部门数据"
},
{
"Enabled": true,
"Key": "GroupHelper-RetrieveGroupsByUserId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "指定用户组数据缓存"
+ "Desc": "通过用户ID获得所有部门数据"
},
{
"Enabled": true,
"Key": "GroupHelper-RetrieveGroupsByRoleId",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "指定角色组数据缓存"
+ "Desc": "通过角色ID获得所有部门数据"
},
{
"Enabled": true,
"Key": "LogHelper-RetrieveLogs",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "所有日志数据缓存"
+ "Desc": "所有日志数据"
},
{
"Enabled": true,
"Key": "DictHelper-RetrieveDictsCategory",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "字典分类数据缓存"
+ "Desc": "字典分类数据"
},
{
"Enabled": true,
"Key": "NotificationHelper-RetrieveNotifications",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "通知管理数据缓存"
+ "Desc": "通知管理数据"
},
{
"Enabled": true,
"Key": "ExceptionHelper-RetrieveExceptions",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "程序异常数据缓存"
+ "Desc": "程序异常数据"
},
{
"Enabled": true,
"Key": "MessageHelper-RetrieveMessages",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "站内消息数据缓存"
+ "Desc": "站内消息数据"
},
{
"Enabled": true,
"Key": "TaskHelper-RetrieveTasks",
"Interval": 600,
"SlidingExpiration": true,
- "Desc": "所有任务数据缓存"
+ "Desc": "所有任务数据"
},
{
"Enabled": true,
"Key": "WebApi",
"Interval": 21600,
"SlidingExpiration": true,
- "Desc": "WebApi 数据缓存"
+ "Desc": "WebApi 数据"
},
{
"Enabled": true,
"Key": "Token",
"Interval": 21600,
"SlidingExpiration": true,
- "Desc": "Token 数据缓存"
+ "Desc": "Token 数据"
},
{
"Enabled": true,
diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs
index 14ae66ce..ab39a2ec 100644
--- a/Bootstrap.DataAccess/CacheCleanUtility.cs
+++ b/Bootstrap.DataAccess/CacheCleanUtility.cs
@@ -45,8 +45,8 @@ namespace Bootstrap.DataAccess
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
});
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
- cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
- corsKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
+ cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
+ corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
}
if (groupIds != null)
{
@@ -79,6 +79,7 @@ namespace Bootstrap.DataAccess
if (cacheKey != null)
{
cacheKeys.Add(cacheKey);
+ corsKeys.Add(cacheKey);
}
CacheManager.Clear(cacheKeys);
CacheManager.CorsClear(corsKeys);
diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs
index ad92e982..dd3dce30 100644
--- a/Bootstrap.DataAccess/UserHelper.cs
+++ b/Bootstrap.DataAccess/UserHelper.cs
@@ -17,10 +17,11 @@ namespace Bootstrap.DataAccess
///
public static class UserHelper
{
- private const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
+ internal const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers";
internal const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
internal const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
+
///
/// 查询所有用户
///
@@ -28,7 +29,7 @@ namespace Bootstrap.DataAccess
///
public static IEnumerable RetrieveUsers()
{
- return CacheManager.GetOrAdd(BootstrapUser.RetrieveUsersDataKey, key =>
+ return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
{
List users = new List();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
@@ -147,6 +148,32 @@ namespace Bootstrap.DataAccess
///
///
///
+ ///
+ ///
+ ///
+ ///
+ public static bool ChangePassword(string userName, string password, string newPass)
+ {
+ bool ret = false;
+ if (BootstrapUser.Authenticate(userName, password))
+ {
+ string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
+ var passSalt = LgbCryptography.GenerateSalt();
+ var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", newPassword));
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", passSalt));
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
+ ret = true;
+ }
+ }
+ return ret;
+ }
+ ///
+ ///
+ ///
///
///
///
@@ -327,13 +354,31 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
- string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
- CacheCleanUtility.ClearCache(cacheKey: key);
+ CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
ret = true;
}
return ret;
}
///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool SaveDisplayName(string userName, string displayName)
+ {
+ bool ret = false;
+ string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", displayName));
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
+ ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
+ CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
+ }
+ return ret;
+ }
+ ///
/// 根据用户名更改用户皮肤
///
///
@@ -348,8 +393,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@cssName", DBAccessFactory.ToDBValue(cssName)));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
- string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
- CacheCleanUtility.ClearCache(cacheKey: key);
+ CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
ret = true;
}
return ret;