重构代码:移除与Bootstrap.Security组件相同功能代码,统一使用组件内的方法,更改缓存Key值,与组件内部一致
This commit is contained in:
parent
13c2f7152f
commit
fc8729903a
|
@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
public ActionResult Lock()
|
||||
{
|
||||
FormsAuthentication.SignOut();
|
||||
var user = UserHelper.RetrieveUsersByName(User.Identity.Name);
|
||||
var user = BootstrapUser.RetrieveUserByUserName(User.Identity.Name);
|
||||
return View(new LockModel
|
||||
{
|
||||
UserName = user.UserName,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Web.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
@ -16,7 +17,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<Menu> Get([FromUri]QueryMenuOption value)
|
||||
public QueryData<BootstrapMenu> Get([FromUri]QueryMenuOption value)
|
||||
{
|
||||
return value.RetrieveData(User.Identity.Name);
|
||||
}
|
||||
|
@ -25,7 +26,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
public bool Post([FromBody]Menu value)
|
||||
public bool Post([FromBody]BootstrapMenu value)
|
||||
{
|
||||
return MenuHelper.SaveMenu(value);
|
||||
}
|
||||
|
@ -38,10 +39,16 @@ namespace Bootstrap.Admin.Controllers
|
|||
{
|
||||
return MenuHelper.DeleteMenu(value);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IEnumerable<Menu> Post(int id, [FromBody]JObject value)
|
||||
public IEnumerable<BootstrapMenu> Post(int id, [FromBody]JObject value)
|
||||
{
|
||||
var ret = new List<Menu>();
|
||||
var ret = new List<BootstrapMenu>();
|
||||
dynamic json = value;
|
||||
switch ((string)json.type)
|
||||
{
|
||||
|
@ -49,13 +56,19 @@ namespace Bootstrap.Admin.Controllers
|
|||
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
|
||||
break;
|
||||
case "user":
|
||||
ret = MenuHelper.RetrieveAllMenusByUserName(User.Identity.Name).ToList();
|
||||
ret = BootstrapMenu.RetrieveAllMenus(User.Identity.Name).ToList();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public bool Put(int id, [FromBody]JObject value)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Security.Principal;
|
||||
using Longbow.Web.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -34,15 +35,15 @@ namespace Bootstrap.Admin.Controllers
|
|||
if (value.UserStatus == 9)
|
||||
{
|
||||
// vlaidate userName
|
||||
return UserHelper.RetrieveUsersByName(value.UserName) == null;
|
||||
return BootstrapUser.RetrieveUserByUserName(value.UserName) == null;
|
||||
}
|
||||
var ret = false;
|
||||
if (value.UserName.Equals(User.Identity.Name, System.StringComparison.OrdinalIgnoreCase) || LgbPrincipal.IsAdmin(User))
|
||||
{
|
||||
if (value.UserStatus == 1)
|
||||
ret = UserHelper.SaveUserInfoByName(value);
|
||||
ret = BootstrapUser.SaveUserInfoByName(value.UserName, value.DisplayName);
|
||||
else if (value.UserStatus == 2)
|
||||
ret = UserHelper.ChangePassword(value);
|
||||
ret = BootstrapUser.ChangePassword(value.UserName, value.Password, value.NewPassword);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -76,9 +77,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public User Get(string userName)
|
||||
public BootstrapUser Get(string userName)
|
||||
{
|
||||
return UserHelper.RetrieveUsersByName(userName);
|
||||
return BootstrapUser.RetrieveUserByUserName(userName);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using System.Web;
|
||||
|
||||
namespace Bootstrap.Admin.Models
|
||||
|
@ -10,20 +11,15 @@ namespace Bootstrap.Admin.Models
|
|||
{
|
||||
public HeaderBarModel()
|
||||
{
|
||||
var user = UserHelper.RetrieveUsersByName(HttpContext.Current.User.Identity.Name);
|
||||
var user = BootstrapUser.RetrieveUserByUserName(HttpContext.Current.User.Identity.Name);
|
||||
Icon = user.Icon;
|
||||
DisplayName = user.DisplayName;
|
||||
UserName = user.UserName;
|
||||
UserId = user.Id;
|
||||
}
|
||||
public string UserName { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int UserId { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DisplayName { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -9,13 +10,13 @@ namespace Bootstrap.Admin.Models
|
|||
{
|
||||
public NavigatorBarModel(string url)
|
||||
{
|
||||
Navigations = MenuHelper.RetrieveNavigationsByUserName(UserName).Where(m => m.IsResource == 0);
|
||||
Navigations = BootstrapMenu.RetrieveSystemMenus(UserName);
|
||||
Applications = DictHelper.RetrieveApps();
|
||||
ActiveMenu(null, Navigations.ToList(), url);
|
||||
HomeUrl = "~/Admin/Index";
|
||||
}
|
||||
|
||||
private void ActiveMenu(Menu parent, List<Menu> menus, string url)
|
||||
private void ActiveMenu(BootstrapMenu parent, List<BootstrapMenu> menus, string url)
|
||||
{
|
||||
menus.ForEach(m =>
|
||||
{
|
||||
|
@ -27,7 +28,7 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public IEnumerable<Menu> Navigations { get; private set; }
|
||||
public IEnumerable<BootstrapMenu> Navigations { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Web.Mvc;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -23,9 +23,9 @@ namespace Bootstrap.Admin.Models
|
|||
/// </summary>
|
||||
public string IsResource { get; set; }
|
||||
|
||||
public QueryData<Menu> RetrieveData(string userName)
|
||||
public QueryData<BootstrapMenu> RetrieveData(string userName)
|
||||
{
|
||||
var data = MenuHelper.RetrieveMenus(userName);
|
||||
var data = BootstrapMenu.RetrieveMenusByUserName(userName);
|
||||
if (!string.IsNullOrEmpty(ParentName))
|
||||
{
|
||||
data = data.Where(t => t.ParentName.Contains(ParentName));
|
||||
|
@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Models
|
|||
{
|
||||
data = data.Where(t => t.IsResource.ToString() == IsResource);
|
||||
}
|
||||
var ret = new QueryData<Menu>();
|
||||
var ret = new QueryData<BootstrapMenu>();
|
||||
ret.total = data.Count();
|
||||
switch (Sort)
|
||||
{
|
||||
|
|
|
@ -37,9 +37,18 @@ namespace Bootstrap.Admin.Models
|
|||
case "UserName":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
|
||||
break;
|
||||
case "DisplayName":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.DisplayName) : data.OrderByDescending(t => t.DisplayName);
|
||||
break;
|
||||
case "RegisterTime":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.RegisterTime) : data.OrderByDescending(t => t.RegisterTime);
|
||||
break;
|
||||
case "ApprovedTime":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.ApprovedTime) : data.OrderByDescending(t => t.ApprovedTime);
|
||||
break;
|
||||
case "ApprovedBy":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.ApprovedBy) : data.OrderByDescending(t => t.ApprovedBy);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
}]
|
||||
},
|
||||
callback: function (data) {
|
||||
if (data && data.success && data.oper === 'save' && data.data.ID === $('#userId').val()) {
|
||||
if (data && data.success && data.oper === 'save') {
|
||||
$('#userDisplayName').text(data.data.DisplayName);
|
||||
}
|
||||
if (data && data.oper === 'create') {
|
||||
|
@ -90,11 +90,17 @@
|
|||
$('table').smartTable({
|
||||
url: User.url, //请求后台的URL(*)
|
||||
sortName: 'DisplayName',
|
||||
sortOrder: "asc",
|
||||
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*)
|
||||
columns: [{ checkbox: true },
|
||||
columns: [
|
||||
{ checkbox: true },
|
||||
{ title: "Id", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
|
||||
{ title: "登陆名称", field: "UserName", sortable: true },
|
||||
{ title: "显示名称", field: "DisplayName", sortable: true }
|
||||
{ title: "显示名称", field: "DisplayName", sortable: true },
|
||||
{ title: "注册时间", field: "RegisterTime", sortable: true },
|
||||
{ title: "授权时间", field: "ApprovedTime", sortable: true },
|
||||
{ title: "授权人", field: "ApprovedBy", sortable: true },
|
||||
{ title: "说明", field: "Description", sortable: false }
|
||||
]
|
||||
});
|
||||
|
||||
|
@ -124,8 +130,8 @@
|
|||
maxlength: 50
|
||||
}
|
||||
}, {
|
||||
userName: {
|
||||
remote: "此登陆名称已存在"
|
||||
}
|
||||
});
|
||||
userName: {
|
||||
remote: "此登陆名称已存在"
|
||||
}
|
||||
});
|
||||
});
|
|
@ -22,7 +22,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<input id="userId" type="text" class="hidden" value="@Model.UserId" />
|
||||
}
|
||||
@section toolbar {
|
||||
<button id="btn_assignRole" type="button" class="btn btn-info">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@model Menu
|
||||
@model Bootstrap.Security.BootstrapMenu
|
||||
<li class="sub-menu">
|
||||
<a href="@Url.Content(Model.Url)" class="@Model.Active" target="@Model.Target"><i class="@Model.Icon"></i>@Model.Name</a>
|
||||
@if (Model.Menus.Count() > 0)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@model IEnumerable<Menu>
|
||||
@model IEnumerable<Bootstrap.Security.BootstrapMenu>
|
||||
<ul class="sub" style="display: none;">
|
||||
@foreach (var menu in Model)
|
||||
{
|
||||
|
|
|
@ -27,12 +27,8 @@
|
|||
</connectionStrings>
|
||||
|
||||
<cacheManager>
|
||||
<add key="MenuHelper-RetrieveMenus" interval="600" desc="所有菜单数据缓存" />
|
||||
<add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" />
|
||||
<add key="MenuHelper-RetrieveMenusByRoleId" interval="600" desc="角色菜单信息缓存" />
|
||||
<add key="UserHelper-RetrieveUsers" interval="600" desc="所有用户数据缓存" />
|
||||
<add key="UserHelper-RetrieveUsersByName" interval="600" desc="指定用户数据缓存" />
|
||||
<add key="UserHelper-RetrieveUsersByRoleId" interval="600" desc="指定角色用户数据缓存" />
|
||||
<add key="UserHelper-RetrieveUsersByGroupId" interval="600" desc="指定组用户数据缓存" />
|
||||
<add key="RoleHelper-RetrieveRoles" interval="600" desc="所有角色数据缓存" />
|
||||
<add key="RoleHelper-RetrieveRolesByUserId" interval="600" desc="指定用户角色数据缓存" />
|
||||
<add key="RoleHelper-RetrieveRolesByMenuId" interval="600" desc="指定菜单角色数据缓存" />
|
||||
|
@ -41,10 +37,8 @@
|
|||
<add key="GroupHelper-RetrieveGroupsByUserId" interval="600" desc="指定用户组数据缓存" />
|
||||
<add key="GroupHelper-RetrieveGroupsByRoleId" interval="600" desc="指定角色组数据缓存" />
|
||||
<add key="LogHelper-RetrieveLogs" interval="600" desc="所有日志数据缓存" />
|
||||
<add key="DictHelper-RetrieveDicts" interval="600" desc="所有字典数据缓存" />
|
||||
<add key="DictHelper-RetrieveDictsCategory" interval="6000" desc="字典分类数据缓存" />
|
||||
<add key="NotificationHelper-RetrieveNotifications" interval="600" desc="通知管理数据缓存" />
|
||||
<add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" />
|
||||
<add key="ExceptionHelper-RetrieveExceptions" interval="600" desc="程序异常数据缓存" />
|
||||
<add key="MessageHelper-RetrieveMessages" interval="600" desc="站内消息数据缓存" />
|
||||
<add key="TaskHelper-RetrieveTasks" interval="600" desc="所有任务数据缓存" />
|
||||
|
@ -53,6 +47,12 @@
|
|||
<add key="BootstrapAdminPrincipal-RetrieveRolesByUserName" interval="600" desc="指定用户名角色数据缓存" />
|
||||
<add key="BootstrapAdminPrincipal-RetrieveAllGroups-BA" interval="600" desc="系统所有用户组列表数据" />
|
||||
<add key="BootstrapAdminPrincipal-RetrieveGroupsByUserName" interval="600" desc="通过用户获得用户组数据" />
|
||||
<add key="BootstrapMenu-RetrieveMenus" interval="600" desc="所有菜单数据缓存" />
|
||||
<add key="BootstrapDict-RetrieveDicts" interval="600" desc="所有字典数据缓存" />
|
||||
<add key="BootstrapUser-RetrieveUsers" interval="600" desc="所有用户数据缓存" />
|
||||
<add key="BootstrapUser-RetrieveUsersByName" interval="600" desc="指定用户数据缓存" />
|
||||
<add key="BootstrapUser-RetrieveUsersByRoleId" interval="600" desc="指定角色用户数据缓存" />
|
||||
<add key="BootstrapUser-RetrieveUsersByGroupId" interval="600" desc="指定组用户数据缓存" />
|
||||
</cacheManager>
|
||||
|
||||
|
||||
|
@ -98,7 +98,7 @@
|
|||
</httpModules>
|
||||
<machineKey validation="SHA1" validationKey="78EA3850338FBADCE59D8DDF58C9E4518E75AC149C46142D7AAD7F1AD49D95D4" decryptionKey="684FC9301F404DE1B9565E7D9520AC579E823307BED44885" />
|
||||
</system.web>
|
||||
|
||||
|
||||
<system.webServer>
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
|
@ -134,7 +134,7 @@
|
|||
<add name="ExceptionManagement" type="Longbow.ExceptionManagement.ExceptionManagementModule, Longbow.ExceptionManagement" />
|
||||
</modules>
|
||||
</system.webServer>
|
||||
|
||||
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
<Compile Include="GroupHelper.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="LogHelper.cs" />
|
||||
<Compile Include="Menu.cs" />
|
||||
<Compile Include="MenuHelper.cs" />
|
||||
<Compile Include="Message.cs" />
|
||||
<Compile Include="MessageHelper.cs" />
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Longbow.Caching;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Caching;
|
||||
using Longbow.Caching.Configuration;
|
||||
using Longbow.ExceptionManagement;
|
||||
using System;
|
||||
|
@ -32,7 +33,7 @@ namespace Bootstrap.DataAccess
|
|||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
||||
}
|
||||
if (userIds != null)
|
||||
{
|
||||
|
@ -40,10 +41,10 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
|
||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
||||
});
|
||||
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
||||
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
||||
cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
|
||||
}
|
||||
if (groupIds != null)
|
||||
{
|
||||
|
@ -53,7 +54,7 @@ namespace Bootstrap.DataAccess
|
|||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
||||
}
|
||||
if (menuIds != null)
|
||||
{
|
||||
|
@ -61,11 +62,11 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
||||
}
|
||||
if (dictIds != null)
|
||||
{
|
||||
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
|
||||
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
||||
}
|
||||
if (logIds != null)
|
||||
{
|
||||
|
@ -88,8 +89,10 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
try
|
||||
{
|
||||
var client = new WebClient();
|
||||
cacheKeys.ForEach(k => client.OpenRead(new Uri(string.Format(ele.Url, k))));
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
cacheKeys.ForEach(k => client.OpenRead(string.Format(ele.Url, k)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -19,7 +19,6 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts";
|
||||
private const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单主键ID
|
||||
/// </summary>
|
||||
public int Id { set; get; }
|
||||
/// <summary>
|
||||
/// 获得/设置 父级菜单ID
|
||||
/// </summary>
|
||||
public int ParentId { set; get; }
|
||||
/// <summary>
|
||||
/// 获得/设置 父级菜单名称
|
||||
/// </summary>
|
||||
public string ParentName { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单序号
|
||||
/// </summary>
|
||||
public int Order { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单URL地址
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单分类
|
||||
/// </summary>
|
||||
public string Category { get; set; }
|
||||
/// <summary>
|
||||
/// 获得 菜单分类名称,取字典表中的Name category="菜单"
|
||||
/// </summary>
|
||||
public string CategoryName { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 是否当前被选中 active为选中
|
||||
/// </summary>
|
||||
public string Active { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 链接目标
|
||||
/// </summary>
|
||||
public string Target { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 是否为资源文件
|
||||
/// </summary>
|
||||
public int IsResource { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 所属应用程序
|
||||
/// </summary>
|
||||
public string ApplicationCode { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public IEnumerable<Menu> Menus { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
using Longbow;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Caching;
|
||||
using Longbow.Caching.Configuration;
|
||||
using Longbow.Data;
|
||||
using Longbow.ExceptionManagement;
|
||||
using Longbow.Security.Principal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -18,96 +17,8 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public static class MenuHelper
|
||||
{
|
||||
internal const string RetrieveMenusDataKey = "MenuHelper-RetrieveMenus";
|
||||
private const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
|
||||
/// <summary>
|
||||
/// 查询所有菜单信息
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Menu> RetrieveMenus(string userName = null)
|
||||
{
|
||||
userName = LgbPrincipal.IsWebAdmin(userName) ? string.Empty : userName;
|
||||
string key = string.Format("{0}-{1}", RetrieveMenusDataKey, userName);
|
||||
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusDataKey), k =>
|
||||
{
|
||||
List<Menu> menus = new List<Menu>();
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RetrieveMenus"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", DBAccess.ToDBValue(userName), ParameterDirection.Input));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
menus.Add(new Menu()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
ParentId = (int)reader[1],
|
||||
Name = (string)reader[2],
|
||||
Order = (int)reader[3],
|
||||
Icon = LgbConvert.ReadValue(reader[4], string.Empty),
|
||||
Url = LgbConvert.ReadValue(reader[5], string.Empty),
|
||||
Category = (string)reader[6],
|
||||
Target = (string)reader[7],
|
||||
IsResource = (bool)reader[8] ? 1 : 0,
|
||||
ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9],
|
||||
CategoryName = (string)reader[10],
|
||||
ParentName = LgbConvert.ReadValue(reader[11], string.Empty)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return menus;
|
||||
}, CacheSection.RetrieveDescByKey(RetrieveMenusDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Menu> RetrieveAllMenusByUserName(string userName)
|
||||
{
|
||||
var navs = RetrieveMenus(userName);
|
||||
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Category).ThenBy(m => m.Order);
|
||||
CascadeMenu(navs, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Menu> RetrieveNavigationsByUserName(string userName)
|
||||
{
|
||||
var navs = RetrieveMenus(userName).Where(m => m.Category == "0");
|
||||
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Order);
|
||||
CascadeMenu(navs, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得前台菜单
|
||||
/// </summary>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Menu> RetrieveLinksByUserName(string userName)
|
||||
{
|
||||
var navs = RetrieveMenus(userName).Where(m => m.Category == "1");
|
||||
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Order);
|
||||
CascadeMenu(navs, root);
|
||||
return root;
|
||||
}
|
||||
private static void CascadeMenu(IEnumerable<Menu> navs, IEnumerable<Menu> level)
|
||||
{
|
||||
level.ToList().ForEach(m =>
|
||||
{
|
||||
m.Menus = navs.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order);
|
||||
CascadeMenu(navs, m.Menus);
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除菜单信息
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
|
@ -136,7 +47,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveMenu(Menu p)
|
||||
public static bool SaveMenu(BootstrapMenu p)
|
||||
{
|
||||
if (string.IsNullOrEmpty(p.Name)) return false;
|
||||
bool ret = false;
|
||||
|
@ -177,12 +88,12 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Menu> RetrieveMenusByRoleId(int roleId)
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
||||
{
|
||||
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
||||
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusByRoleIdDataKey), k =>
|
||||
{
|
||||
List<Menu> menus = new List<Menu>();
|
||||
var menus = new List<BootstrapMenu>();
|
||||
try
|
||||
{
|
||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||
|
@ -193,7 +104,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
menus.Add(new Menu()
|
||||
menus.Add(new BootstrapMenu()
|
||||
{
|
||||
Id = (int)reader[0]
|
||||
});
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using Bootstrap.Security;
|
||||
using System;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户表实体类
|
||||
/// </summary>
|
||||
public class User : Longbow.Security.Principal.LgbUser
|
||||
public class User : BootstrapUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得/设置 用户主键ID
|
||||
|
@ -60,10 +61,6 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public string RejectedTime { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 用户头像
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 新密码
|
||||
/// </summary>
|
||||
public string NewPassword { get; set; }
|
||||
|
|
|
@ -5,7 +5,6 @@ using Longbow.Caching.Configuration;
|
|||
using Longbow.Data;
|
||||
using Longbow.ExceptionManagement;
|
||||
using Longbow.Security;
|
||||
using Longbow.Security.Principal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
@ -20,23 +19,21 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public static class UserHelper
|
||||
{
|
||||
internal const string RetrieveUsersDataKey = "UserHelper-RetrieveUsers";
|
||||
private const string RetrieveUsersByNameDataKey = "UserHelper-RetrieveUsersByName";
|
||||
internal const string RetrieveUsersByRoleIdDataKey = "UserHelper-RetrieveUsersByRoleId";
|
||||
internal const string RetrieveUsersByGroupIdDataKey = "UserHelper-RetrieveUsersByGroupId";
|
||||
private const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
|
||||
internal const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
|
||||
internal const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
|
||||
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
|
||||
/// <summary>
|
||||
/// 查询所有用户
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<User> RetrieveUsers(int id = 0)
|
||||
public static IEnumerable<User> RetrieveUsers()
|
||||
{
|
||||
string sql = "select ID, UserName, DisplayName, RegisterTime, ApprovedTime from Users Where ApprovedTime is not null";
|
||||
var ret = CacheManager.GetOrAdd(RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersDataKey), key =>
|
||||
return CacheManager.GetOrAdd(BootstrapUser.RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(BootstrapUser.RetrieveUsersDataKey), key =>
|
||||
{
|
||||
List<User> users = new List<User>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
|
@ -49,52 +46,16 @@ namespace Bootstrap.DataAccess
|
|||
UserName = (string)reader[1],
|
||||
DisplayName = (string)reader[2],
|
||||
RegisterTime = (DateTime)reader[3],
|
||||
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue)
|
||||
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
|
||||
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
|
||||
Description = (string)reader[6]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return users;
|
||||
}, CacheSection.RetrieveDescByKey(RetrieveUsersDataKey));
|
||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据用户名查询用户
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static User RetrieveUsersByName(string userName)
|
||||
{
|
||||
if (LgbPrincipal.IsWebAdmin(userName)) return new User() { DisplayName = "网站管理员", UserName = userName, Icon = "~/Content/images/uploader/default.jpg" };
|
||||
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
|
||||
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
|
||||
{
|
||||
User user = null;
|
||||
string sql = "select u.ID, UserName, DisplayName, RegisterTime, ApprovedTime, case isnull(d.Code, '') when '' then '~/Content/images/uploader/' else d.Code end + Icon from Users u left join Dicts d on d.Define = '0' and d.Category = N'头像地址' and Name = N'头像路径' where ApprovedTime is not null and UserName = @UserName";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
user = new User()
|
||||
{
|
||||
Id = (int)reader[0],
|
||||
UserName = (string)reader[1],
|
||||
DisplayName = (string)reader[2],
|
||||
RegisterTime = (DateTime)reader[3],
|
||||
ApprovedTime = (DateTime)reader[4],
|
||||
Icon = (string)reader[5]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return user;
|
||||
}, CacheSection.RetrieveDescByKey(RetrieveUsersByNameDataKey));
|
||||
}, CacheSection.RetrieveDescByKey(BootstrapUser.RetrieveUsersDataKey));
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询所有的新注册用户
|
||||
|
@ -376,64 +337,5 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveUserInfoByName(User user)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
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", user.DisplayName));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
CacheCleanUtility.ClearCache(userIds: string.Empty);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ChangePassword(User user)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
if (BootstrapUser.Authenticate(user.UserName, user.Password))
|
||||
{
|
||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
|
||||
user.PassSalt = LgbCryptography.GenerateSalt();
|
||||
user.NewPassword = LgbCryptography.ComputeHash(user.NewPassword, user.PassSalt);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", user.NewPassword));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", user.PassSalt));
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, user.UserName);
|
||||
CacheManager.Clear(k => k == key);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue