feat(#I12VKS): 登陆页面网站标题与默认应用一致

comment #I12VKS

link #I12VKS

# Conflicts:
#	src/client/Bootstrap.Client/Bootstrap.Client.csproj
This commit is contained in:
Argo Zhang 2019-10-01 13:47:56 +08:00
parent f30189ef44
commit 7017843a49
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
11 changed files with 34 additions and 20 deletions

View File

@ -11,7 +11,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.Tasks" Version="2.2.23" />
<PackageReference Include="Microsoft.AspNetCore.App" />

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,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
/// <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,6 +27,14 @@ namespace Bootstrap.Admin.Models
EnableAutoLockScreen = DictHelper.RetrieveAutoLockScreen();
}
/// <summary>
/// 默认构造函数
/// </summary>
public ModelBase() : this("0")
{
}
/// <summary>
/// 获取 网站标题
/// </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

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.17" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta1" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.13" />
<PackageReference Include="Microsoft.AspNetCore.App" />

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

@ -5,7 +5,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 Newtonsoft.Json;