!37 增加功能:登陆页面标题与前台系统标题一致

Merge pull request !37 from Argo/dev-fix
This commit is contained in:
Argo 2019-10-01 13:57:04 +08:00 committed by Gitee
commit 99b5b00ac3
14 changed files with 56 additions and 31 deletions

View File

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.0" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta1" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="3.0.0" />
<PackageReference Include="Longbow.Tasks" Version="2.2.24" />

View File

@ -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
/// <summary>
/// 系统登录方法
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
[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));
}
/// <summary>
@ -125,12 +127,13 @@ namespace Bootstrap.Admin.Controllers
/// <param name="userName">User name.</param>
/// <param name="password">Password.</param>
/// <param name="remember">Remember.</param>
/// <param name="appId"></param>
[HttpPost]
public async Task<IActionResult> Login(string userName, string password, string remember)
public async Task<IActionResult> 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<IActionResult> SignInAsync(string userName, bool persistent, string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme)
@ -163,12 +166,13 @@ namespace Bootstrap.Admin.Controllers
/// <summary>
/// Logout this instance.
/// </summary>
/// <param name="appId"></param>
/// <returns>The logout.</returns>
[HttpGet]
public async Task<IActionResult> Logout()
public async Task<IActionResult> Logout([FromQuery]string appId = "0")
{
await HttpContext.SignOutAsync();
return Redirect(Request.PathBase + CookieAuthenticationDefaults.LoginPath);
return Redirect(QueryHelpers.AddQueryString(Request.PathBase + CookieAuthenticationDefaults.LoginPath, "AppId", appId));
}
/// <summary>

View File

@ -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);
}

View File

@ -21,9 +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(AppId);
Footer = DictHelper.RetrieveWebFooter(AppId);
}
}
@ -50,7 +54,7 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 获得 当前设置的默认应用
/// </summary>
public string AppCode { get; }
public string AppId { get; }
/// <summary>
/// 获得 当前样式

View File

@ -10,7 +10,8 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 默认构造函数
/// </summary>
public LoginModel()
/// <param name="appId"></param>
public LoginModel(string appId = "0") : base(appId)
{
ImageLibUrl = DictHelper.RetrieveImagesLibUrl();
}

View File

@ -10,10 +10,11 @@ namespace Bootstrap.Admin.Models
/// <summary>
/// 默认构造函数
/// </summary>
public ModelBase()
/// <param name="appId"></param>
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,15 +27,23 @@ namespace Bootstrap.Admin.Models
EnableAutoLockScreen = DictHelper.RetrieveAutoLockScreen();
}
/// <summary>
/// 默认构造函数
/// </summary>
public ModelBase() : this("0")
{
}
/// <summary>
/// 获取 网站标题
/// </summary>
public string Title { get; private set; }
public string Title { get; protected set; }
/// <summary>
/// 获取 网站页脚
/// </summary>
public string Footer { get; private set; }
public string Footer { get; protected set; }
/// <summary>
/// 网站样式全局设置

View File

@ -87,7 +87,7 @@
<div class="card-body">
<div class="form-group">
<div class="btn-group" role="group">
<button id="app" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="" value="@Model.AppCode">未设置</button>
<button id="app" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="" value="@Model.AppId">未设置</button>
<div class="dropdown-menu">
@foreach (var app in Model.Applications)
{

View File

@ -112,7 +112,7 @@
<a href="~/Admin/Notifications"><i class="fa fa-bell"></i>通知<span id="logoutNoti" class="badge badge-pill badge-success"></span></a>
</div>
<div class="dropdown-item">
<a href="~/Account/Logout"><i class="fa fa-key"></i>注销</a>
<a href="~/Account/Logout?appId=@Model.AppId"><i class="fa fa-key"></i>注销</a>
</div>
</div>
</div>

View File

@ -74,21 +74,23 @@ namespace Bootstrap.DataAccess.MongoDB
}
/// <summary>
///
/// 获得网站标题设置
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
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;
}
/// <summary>
///
/// 获得网站页脚设置
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
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 © 通用后台管理系统";

View File

@ -63,11 +63,13 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获取系统网站标题
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
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
/// <summary>
/// 获取系统网站页脚
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
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;
}

View File

@ -98,14 +98,16 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获取站点 Title 配置信息
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
public static string RetrieveWebTitle(string appId = "0") => DbContextManager.Create<Dict>().RetrieveWebTitle(appId);
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <param name="appId"></param>
/// <returns></returns>
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
public static string RetrieveWebFooter(string appId = "0") => DbContextManager.Create<Dict>().RetrieveWebFooter(appId);
/// <summary>
/// 获得系统中配置的可以使用的网站样式

View File

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.0" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta1" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.0.0" />

View File

@ -29,6 +29,7 @@ namespace Bootstrap.Client.Models
var authHost = ConfigurationManager.Get<BootstrapAdminAuthenticationOptions>().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

View File

@ -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;