From 4fee48124a4879980df5114f72fee4d9374888d6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 1 Oct 2019 10:29:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(#I12VKS):=20=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E6=A0=87=E9=A2=98=E9=A1=B5=E8=84=9A=E4=B8=8E?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=BA=94=E7=94=A8=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit comment #I12VKS 已登陆用户后台管理页面显示的网站标题跟页脚与个人中心设置的默认应用内设置的显示一致 link #I12VKS --- src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs | 4 ++++ src/admin/Bootstrap.Admin/Models/ModelBase.cs | 4 ++-- src/admin/Bootstrap.DataAccess.MongoDB/Dict.cs | 12 +++++++----- src/admin/Bootstrap.DataAccess/Dict.cs | 11 +++++++---- src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs | 6 ++++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs index aeab1773..6297ab60 100644 --- a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -24,6 +24,10 @@ namespace Bootstrap.Admin.Models AppCode = user.App; Css = user.Css; ActiveCss = string.IsNullOrEmpty(Css) ? Theme : Css; + + // 通过 AppCode 获取用户默认应用的标题 + Title = DictHelper.RetrieveWebTitle(AppCode); + Footer = DictHelper.RetrieveWebFooter(AppCode); } } diff --git a/src/admin/Bootstrap.Admin/Models/ModelBase.cs b/src/admin/Bootstrap.Admin/Models/ModelBase.cs index cb445d5f..50dcdc3c 100644 --- a/src/admin/Bootstrap.Admin/Models/ModelBase.cs +++ b/src/admin/Bootstrap.Admin/Models/ModelBase.cs @@ -29,12 +29,12 @@ namespace Bootstrap.Admin.Models /// /// 获取 网站标题 /// - public string Title { get; private set; } + public string Title { get; protected set; } /// /// 获取 网站页脚 /// - public string Footer { get; private set; } + public string Footer { get; protected set; } /// /// 网站样式全局设置 diff --git a/src/admin/Bootstrap.DataAccess.MongoDB/Dict.cs b/src/admin/Bootstrap.DataAccess.MongoDB/Dict.cs index 1f067f5a..b5d131a1 100644 --- a/src/admin/Bootstrap.DataAccess.MongoDB/Dict.cs +++ b/src/admin/Bootstrap.DataAccess.MongoDB/Dict.cs @@ -74,21 +74,23 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// 获得网站标题设置 /// + /// /// - public override string RetrieveWebTitle() + public override string RetrieveWebTitle(string appId = "0") { - var code = RetrieveAppName("网站标题"); + var code = RetrieveAppName("网站标题", appId); if (code == "网站标题未设置") code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0)?.Code ?? "后台管理系统"; return code; } /// - /// + /// 获得网站页脚设置 /// + /// /// - public override string RetrieveWebFooter() + public override string RetrieveWebFooter(string appId = "0") { var code = RetrieveAppName("网站页脚"); if (code == "网站页脚未设置") code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0)?.Code ?? "2016 © 通用后台管理系统"; diff --git a/src/admin/Bootstrap.DataAccess/Dict.cs b/src/admin/Bootstrap.DataAccess/Dict.cs index a28b9e27..66de0427 100644 --- a/src/admin/Bootstrap.DataAccess/Dict.cs +++ b/src/admin/Bootstrap.DataAccess/Dict.cs @@ -63,11 +63,13 @@ namespace Bootstrap.DataAccess /// /// 获取系统网站标题 /// + /// /// - public virtual string RetrieveWebTitle() + public virtual string RetrieveWebTitle(string appId = "0") { // 优先查找配置的应用程序网站标题 - var code = DbHelper.RetrieveTitle(); + var code = DbHelper.RetrieveTitle(appId); + if (code == "网站标题未设置") code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0)?.Code ?? "后台管理系统"; return code; } @@ -75,11 +77,12 @@ namespace Bootstrap.DataAccess /// /// 获取系统网站页脚 /// + /// /// - public virtual string RetrieveWebFooter() + public virtual string RetrieveWebFooter(string appId = "0") { // 优先查找配置的应用程序网站标题 - var code = DbHelper.RetrieveFooter(); + var code = DbHelper.RetrieveFooter(appId); if (code == "网站页脚未设置") code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0)?.Code ?? "2016 © 通用后台管理系统"; return code; } diff --git a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs index ca3e2465..7ba70dc8 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -98,14 +98,16 @@ namespace Bootstrap.DataAccess /// /// 获取站点 Title 配置信息 /// + /// /// - public static string RetrieveWebTitle() => DbContextManager.Create().RetrieveWebTitle(); + public static string RetrieveWebTitle(string appId = "0") => DbContextManager.Create().RetrieveWebTitle(appId); /// /// 获取站点 Footer 配置信息 /// + /// /// - public static string RetrieveWebFooter() => DbContextManager.Create().RetrieveWebFooter(); + public static string RetrieveWebFooter(string appId = "0") => DbContextManager.Create().RetrieveWebFooter(appId); /// /// 获得系统中配置的可以使用的网站样式 From 23e60caa03bb22b56668d5b08822571cbdc65d82 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 1 Oct 2019 13:47:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(#I12VKS):=20=E7=99=BB=E9=99=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=BD=91=E7=AB=99=E6=A0=87=E9=A2=98=E4=B8=8E?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=BA=94=E7=94=A8=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit comment #I12VKS link #I12VKS --- src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj | 2 +- .../Controllers/AccountController.cs | 16 ++++++++++------ .../Controllers/HomeController.cs | 2 +- .../Bootstrap.Admin/Models/HeaderBarModel.cs | 8 ++++---- src/admin/Bootstrap.Admin/Models/LoginModel.cs | 3 ++- src/admin/Bootstrap.Admin/Models/ModelBase.cs | 15 ++++++++++++--- .../Bootstrap.Admin/Views/Admin/Profiles.cshtml | 2 +- .../Bootstrap.Admin/Views/Shared/Header.cshtml | 2 +- .../Bootstrap.Client/Bootstrap.Client.csproj | 2 +- .../Bootstrap.Client/Models/HeaderBarModel.cs | 1 + src/client/Bootstrap.Client/Startup.cs | 1 - 11 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj b/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj index b7fd7374..49055a8c 100644 --- a/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs index 5ef4b84d..e81a8dc1 100644 --- a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Configuration; using System; using System.Linq; @@ -67,16 +68,17 @@ namespace Bootstrap.Admin.Controllers /// /// 系统登录方法 /// + /// /// [HttpGet] - public ActionResult Login() + public ActionResult Login([FromQuery] string appId = "0") { if (DictHelper.RetrieveSystemModel()) { ViewBag.UserName = "Admin"; ViewBag.Password = "123789"; } - return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View("Login", new LoginModel()); + return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View("Login", new LoginModel(appId)); } /// @@ -125,12 +127,13 @@ namespace Bootstrap.Admin.Controllers /// User name. /// Password. /// Remember. + /// [HttpPost] - public async Task Login(string userName, string password, string remember) + public async Task Login(string userName, string password, string remember, string appId = "0") { var auth = UserHelper.Authenticate(userName, password); HttpContext.Log(userName, auth); - return auth ? await SignInAsync(userName, remember == "true") : View("Login", new LoginModel() { AuthFailed = true }); + return auth ? await SignInAsync(userName, remember == "true") : View("Login", new LoginModel(appId) { AuthFailed = true }); } private async Task SignInAsync(string userName, bool persistent, string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme) @@ -163,12 +166,13 @@ namespace Bootstrap.Admin.Controllers /// /// Logout this instance. /// + /// /// The logout. [HttpGet] - public async Task Logout() + public async Task Logout([FromQuery]string appId = "0") { await HttpContext.SignOutAsync(); - return Redirect(Request.PathBase + CookieAuthenticationDefaults.LoginPath); + return Redirect(QueryHelpers.AddQueryString(Request.PathBase + CookieAuthenticationDefaults.LoginPath, "AppId", appId)); } /// diff --git a/src/admin/Bootstrap.Admin/Controllers/HomeController.cs b/src/admin/Bootstrap.Admin/Controllers/HomeController.cs index ae9b5843..be2e6c84 100644 --- a/src/admin/Bootstrap.Admin/Controllers/HomeController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/HomeController.cs @@ -19,7 +19,7 @@ namespace Bootstrap.Admin.Controllers { var model = new HeaderBarModel(User.Identity); if (string.IsNullOrEmpty(model.UserName)) return Redirect(Request.PathBase + CookieAuthenticationDefaults.LogoutPath); - var url = DictHelper.RetrieveHomeUrl(model.AppCode); + var url = DictHelper.RetrieveHomeUrl(model.AppId); return url.Equals("~/Home/Index", System.StringComparison.OrdinalIgnoreCase) ? (IActionResult)View(model) : Redirect(url); } diff --git a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs index 6297ab60..925b99f6 100644 --- a/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/src/admin/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -21,13 +21,13 @@ namespace Bootstrap.Admin.Models Icon = user.Icon.Contains("://", StringComparison.OrdinalIgnoreCase) ? user.Icon : string.Format("{0}{1}", DictHelper.RetrieveIconFolderPath(), user.Icon); DisplayName = user.DisplayName; UserName = user.UserName; - AppCode = user.App; + AppId = user.App; Css = user.Css; ActiveCss = string.IsNullOrEmpty(Css) ? Theme : Css; // 通过 AppCode 获取用户默认应用的标题 - Title = DictHelper.RetrieveWebTitle(AppCode); - Footer = DictHelper.RetrieveWebFooter(AppCode); + Title = DictHelper.RetrieveWebTitle(AppId); + Footer = DictHelper.RetrieveWebFooter(AppId); } } @@ -54,7 +54,7 @@ namespace Bootstrap.Admin.Models /// /// 获得 当前设置的默认应用 /// - public string AppCode { get; } + public string AppId { get; } /// /// 获得 当前样式 diff --git a/src/admin/Bootstrap.Admin/Models/LoginModel.cs b/src/admin/Bootstrap.Admin/Models/LoginModel.cs index 2db09765..1870ba6c 100644 --- a/src/admin/Bootstrap.Admin/Models/LoginModel.cs +++ b/src/admin/Bootstrap.Admin/Models/LoginModel.cs @@ -10,7 +10,8 @@ namespace Bootstrap.Admin.Models /// /// 默认构造函数 /// - public LoginModel() + /// + public LoginModel(string appId = "0") : base(appId) { ImageLibUrl = DictHelper.RetrieveImagesLibUrl(); } diff --git a/src/admin/Bootstrap.Admin/Models/ModelBase.cs b/src/admin/Bootstrap.Admin/Models/ModelBase.cs index 50dcdc3c..8f5da079 100644 --- a/src/admin/Bootstrap.Admin/Models/ModelBase.cs +++ b/src/admin/Bootstrap.Admin/Models/ModelBase.cs @@ -10,10 +10,11 @@ namespace Bootstrap.Admin.Models /// /// 默认构造函数 /// - public ModelBase() + /// + public ModelBase(string appId = "0") { - Title = DictHelper.RetrieveWebTitle(); - Footer = DictHelper.RetrieveWebFooter(); + Title = DictHelper.RetrieveWebTitle(appId); + Footer = DictHelper.RetrieveWebFooter(appId); Theme = DictHelper.RetrieveActiveTheme(); IsDemo = DictHelper.RetrieveSystemModel(); ShowCardTitle = DictHelper.RetrieveCardTitleStatus() ? "" : "no-card-header"; @@ -26,6 +27,14 @@ namespace Bootstrap.Admin.Models EnableAutoLockScreen = DictHelper.RetrieveAutoLockScreen(); } + /// + /// 默认构造函数 + /// + public ModelBase() : this("0") + { + + } + /// /// 获取 网站标题 /// diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Profiles.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Profiles.cshtml index 20d02f35..e57c1493 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Profiles.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Profiles.cshtml @@ -87,7 +87,7 @@
- +
diff --git a/src/client/Bootstrap.Client/Bootstrap.Client.csproj b/src/client/Bootstrap.Client/Bootstrap.Client.csproj index 7cc814af..921aa772 100644 --- a/src/client/Bootstrap.Client/Bootstrap.Client.csproj +++ b/src/client/Bootstrap.Client/Bootstrap.Client.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/client/Bootstrap.Client/Models/HeaderBarModel.cs b/src/client/Bootstrap.Client/Models/HeaderBarModel.cs index 4873c4ee..419d6a08 100644 --- a/src/client/Bootstrap.Client/Models/HeaderBarModel.cs +++ b/src/client/Bootstrap.Client/Models/HeaderBarModel.cs @@ -29,6 +29,7 @@ namespace Bootstrap.Client.Models var authHost = ConfigurationManager.Get().AuthHost; var uriBuilder = new UriBuilder(authHost); uriBuilder.Path = uriBuilder.Path == "/" ? CookieAuthenticationDefaults.LogoutPath.Value : $"{uriBuilder.Path.TrimEnd('/')}{CookieAuthenticationDefaults.LogoutPath.Value}"; + uriBuilder.Query = $"AppId={AppId}"; LogoutUrl = uriBuilder.ToString(); // set Icon diff --git a/src/client/Bootstrap.Client/Startup.cs b/src/client/Bootstrap.Client/Startup.cs index c81ae680..b5180699 100644 --- a/src/client/Bootstrap.Client/Startup.cs +++ b/src/client/Bootstrap.Client/Startup.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;