增加功能:配置文件中的时长配置移动到字典表配置中 link #ITAK4
#Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITAK4
This commit is contained in:
parent
90b16c5b02
commit
ac8982f611
|
@ -47,7 +47,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
{
|
||||
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties() { ExpiresUtc = DateTimeOffset.Now.AddDays(LgbConvert.ReadValue(ConfigurationManager.AppSettings["CookieExpiresDays"], 7)), IsPersistent = remember == "true" });
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties { ExpiresUtc = DateTimeOffset.Now.AddDays(DictHelper.RetrieveCookieExpiresPeriod()), IsPersistent = remember == "true" });
|
||||
}
|
||||
// redirect origin url
|
||||
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault() ?? "~/Home/Index";
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
"AllowOrigins": "http://localhost:49823",
|
||||
"KeyPath": "..\\keys",
|
||||
"DisableAutomaticKeyGeneration": false,
|
||||
"KeepExceptionsPeriod": 1,
|
||||
"KeepLogsPeriod": 1,
|
||||
"LongbowCache": {
|
||||
"Enabled": false,
|
||||
"CorsItems": [
|
||||
|
|
|
@ -62,10 +62,6 @@
|
|||
"Expires": 5,
|
||||
"SecurityKey": "BootstrapAdmin-V1.1"
|
||||
},
|
||||
"KeepExceptionsPeriod": 12,
|
||||
"KeepLogsPeriod": 12,
|
||||
"CookieExpiresDays": 7,
|
||||
"KeepLoginLogsPeriod": 7,
|
||||
"LongbowCache": {
|
||||
"Enabled": true,
|
||||
"CorsItems": [
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -89,7 +90,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 获取头像路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string RetrieveIconFolderPath() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }).Code;
|
||||
public virtual string RetrieveIconFolderPath() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict { Code = "~/images/uploader/" }).Code;
|
||||
|
||||
/// <summary>
|
||||
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||
|
@ -126,5 +127,29 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<BootstrapDict> RetrieveDicts() => DbHelper.RetrieveDicts();
|
||||
|
||||
/// <summary>
|
||||
/// 程序异常时长 默认1月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "程序异常保留时长" && d.Define == 0).FirstOrDefault()?.Code, 1);
|
||||
|
||||
/// <summary>
|
||||
/// 操作日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "操作日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "登录日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
||||
|
||||
/// <summary>
|
||||
/// Cookie保存时长 默认7天
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "Cookie保留时长" && d.Define == 0).FirstOrDefault()?.Code, 7);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Bootstrap.DataAccess
|
|||
|
||||
private static void ClearExceptions() => System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
DbManager.Create().Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)));
|
||||
DbManager.Create().Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
|
@ -79,7 +79,7 @@ namespace Bootstrap.DataAccess
|
|||
if (ex == null) return true;
|
||||
|
||||
var errorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
|
||||
DbManager.Create().Insert(new Exceptions()
|
||||
DbManager.Create().Insert(new Exceptions
|
||||
{
|
||||
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
|
||||
ErrorPage = errorPage,
|
||||
|
@ -106,7 +106,6 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="po"></param>
|
||||
/// <param name="startTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime)
|
||||
{
|
||||
|
|
|
@ -115,5 +115,29 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbContextManager.Create<Dict>().RetrieveApps();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveExceptionsLogPeriod() => DbContextManager.Create<Dict>().RetrieveExceptionsLogPeriod();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveLogsPeriod() => DbContextManager.Create<Dict>().RetrieveLogsPeriod();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveLoginLogsPeriod() => DbContextManager.Create<Dict>().RetrieveLoginLogsPeriod();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveCookieExpiresPeriod() => DbContextManager.Create<Dict>().RetrieveCookieExpiresPeriod();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using Longbow;
|
||||
using Longbow.Configuration;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
|
@ -58,20 +56,18 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 查询所有日志信息
|
||||
/// </summary>
|
||||
/// <param name="tId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Log> Retrieves() => DbManager.Create().Fetch<Log>("select * from Logs where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
|
||||
|
||||
/// <summary>
|
||||
/// 删除日志信息
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
private static void DeleteLogAsync()
|
||||
{
|
||||
System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var dtm = DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1));
|
||||
var dtm = DateTime.Now.AddMonths(0 - DictHelper.RetrieveLogsPeriod());
|
||||
DbManager.Create().Execute("delete from Logs where LogTime < @0", dtm);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using Longbow;
|
||||
using Longbow.Configuration;
|
||||
using PetaPoco;
|
||||
using PetaPoco;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -64,15 +62,10 @@ namespace Bootstrap.DataAccess
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected const string KeepLoginLogsPeriodKey = "KeepLoginLogsPeriod";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<LoginUser> Retrieves() => DbManager.Create().Fetch<LoginUser>("Where LoginTime > @0 Order by LoginTime desc", DateTime.Today.AddDays(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings[KeepLoginLogsPeriodKey], 7)));
|
||||
public virtual IEnumerable<LoginUser> Retrieves() => DbManager.Create().Fetch<LoginUser>("Where LoginTime > @0 Order by LoginTime desc", DateTime.Today.AddMonths(0 - DictHelper.RetrieveLoginLogsPeriod()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,14 @@ INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站样
|
|||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'当前样式', N'使用样式', N'blue.css', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站设置', N'前台首页', N'~/Home/Index', 0)
|
||||
|
||||
-- 时长单位 月
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'程序异常保留时长', '1', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'操作日志保留时长', '12', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'登录日志保留时长', '12', 0)
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'Cookie保留时长', '7', 0)
|
||||
|
||||
DELETE FROM Navigations
|
||||
SET IDENTITY_INSERT [dbo].[Navigations] ON
|
||||
INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (1, 0, N'后台管理', 10, N'fa fa-gear', N'~/Admin/Index', N'0')
|
||||
|
|
|
@ -278,5 +278,33 @@
|
|||
"Name": "2",
|
||||
"Code": "http://localhost:49185/",
|
||||
"Define": NumberInt(0)
|
||||
},
|
||||
{
|
||||
"_id": ObjectId("5bd6c73d5fa31256f77e4a40"),
|
||||
"Category": "系统设置",
|
||||
"Name": "程序异常保留时长",
|
||||
"Code": "1",
|
||||
"Define": NumberInt(0)
|
||||
},
|
||||
{
|
||||
"_id": ObjectId("5bd6c73d5fa31256f77e4a41"),
|
||||
"Category": "系统设置",
|
||||
"Name": "操作日志保留时长",
|
||||
"Code": "12",
|
||||
"Define": NumberInt(0)
|
||||
},
|
||||
{
|
||||
"_id": ObjectId("5bd6c73d5fa31256f77e4a42"),
|
||||
"Category": "系统设置",
|
||||
"Name": "登录日志保留时长",
|
||||
"Code": "12",
|
||||
"Define": NumberInt(0)
|
||||
},
|
||||
{
|
||||
"_id": ObjectId("5bd6c73d5fa31256f77e4a43"),
|
||||
"Category": "系统设置",
|
||||
"Name": "Cookie保留时长",
|
||||
"Code": "7",
|
||||
"Define": NumberInt(0)
|
||||
}
|
||||
]
|
|
@ -28,6 +28,14 @@ INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站样式
|
|||
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0);
|
||||
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站设置', '前台首页', '~/Home/Index', 0);
|
||||
|
||||
-- 时长单位 月
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
||||
DELETE FROM Navigations;
|
||||
ALTER TABLE Navigations MODIFY COLUMN ID INT NOT NULL;
|
||||
INSERT INTO Navigations (ID, ParentId, Name, `Order`, Icon, Url, Category) VALUES (1, 0, '后台管理', 10, 'fa fa-gear', '~/Admin/Index', '0');
|
||||
|
|
|
@ -28,6 +28,14 @@ INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('网站样式', '黑色
|
|||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('当前样式', '使用样式', 'blue.css', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('网站设置', '前台首页', '~/Home/Index', 0);
|
||||
|
||||
-- 时长单位 月
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
||||
DELETE FROM Navigations;
|
||||
ALTER SEQUENCE navigations_id_seq RESTART WITH 1;
|
||||
INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '后台管理', 10, 'fa fa-gear', '~/Admin/Index', '0');
|
||||
|
|
|
@ -26,6 +26,14 @@ INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '
|
|||
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0);
|
||||
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站设置', '前台首页', '~/Home/Index', 0);
|
||||
|
||||
-- 时长单位 月
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
||||
DELETE FROM Navigations;
|
||||
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '后台管理', 10, 'fa fa-gear', '~/Admin/Index', '0');
|
||||
INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '个人中心', 20, 'fa fa-suitcase', '~/Admin/Profiles', '0');
|
||||
|
|
|
@ -96,5 +96,33 @@ namespace Bootstrap.DataAccess
|
|||
var dict = new Dict();
|
||||
Assert.NotEmpty(dict.RetrieveDicts());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveCookieExpiresPeriod_Ok()
|
||||
{
|
||||
var dict = new Dict();
|
||||
Assert.Equal(7, dict.RetrieveCookieExpiresPeriod());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveExceptionsLogPeriod_Ok()
|
||||
{
|
||||
var dict = new Dict();
|
||||
Assert.Equal(1, dict.RetrieveExceptionsLogPeriod());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveLoginLogsPeriod_Ok()
|
||||
{
|
||||
var dict = new Dict();
|
||||
Assert.Equal(12, dict.RetrieveLoginLogsPeriod());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveLogsPeriod_Ok()
|
||||
{
|
||||
var dict = new Dict();
|
||||
Assert.Equal(12, dict.RetrieveLogsPeriod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue