重构代码:删除AccountController,使用BA后台的登录/登出/权限拒绝页面
This commit is contained in:
parent
8932b790a6
commit
7c49d36ebb
|
@ -1,44 +0,0 @@
|
|||
using Longbow.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Bootstrap.Client.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Account controller.
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public class AccountController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult Login()
|
||||
{
|
||||
var originUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(originUrl)) originUrl = $"?{CookieAuthenticationDefaults.ReturnUrlParameter}={HttpUtility.UrlEncode(originUrl)}";
|
||||
return Redirect($"{ConfigurationManager.AppSettings["AuthHost"]}{CookieAuthenticationDefaults.LoginPath}{originUrl}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Logout this instance.
|
||||
/// </summary>
|
||||
/// <returns>The logout.</returns>
|
||||
public IActionResult Logout()
|
||||
{
|
||||
return Redirect($"{ConfigurationManager.AppSettings["AuthHost"]}{CookieAuthenticationDefaults.LogoutPath}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Accesses the denied.
|
||||
/// </summary>
|
||||
/// <returns>The denied.</returns>
|
||||
[ResponseCache(Duration = 600)]
|
||||
public ActionResult AccessDenied()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
using Bootstrap.Client.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using System;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Bootstrap.Client.Models
|
||||
|
@ -22,6 +24,8 @@ namespace Bootstrap.Client.Models
|
|||
UserName = user.UserName;
|
||||
SettingsUrl = DictHelper.RetrieveSettingsUrl();
|
||||
ProfilesUrl = DictHelper.RetrieveProfilesUrl();
|
||||
var uriBuilder = new UriBuilder(ConfigurationManager.AppSettings["AuthHost"]) { Path = CookieAuthenticationDefaults.LogoutPath };
|
||||
LogoutUrl = uriBuilder.ToString();
|
||||
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -39,10 +43,14 @@ namespace Bootstrap.Client.Models
|
|||
/// <summary>
|
||||
/// 获得/设置 设置网址
|
||||
/// </summary>
|
||||
public string SettingsUrl { get; set; }
|
||||
public string SettingsUrl { get; }
|
||||
/// <summary>
|
||||
/// 获得/设置 个人中心网址
|
||||
/// </summary>
|
||||
public string ProfilesUrl { get; set; }
|
||||
public string ProfilesUrl { get; }
|
||||
/// <summary>
|
||||
/// 获得 退出登录地址
|
||||
/// </summary>
|
||||
public string LogoutUrl { get; set; }
|
||||
}
|
||||
}
|
|
@ -19,11 +19,11 @@ namespace Bootstrap.Client.Models
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Title { get; private set; }
|
||||
public string Title { get; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Footer { get; private set; }
|
||||
public string Footer { get; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -20,6 +20,6 @@ namespace Bootstrap.Client.Models
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public IEnumerable<BootstrapMenu> Navigations { get; private set; }
|
||||
public IEnumerable<BootstrapMenu> Navigations { get;}
|
||||
}
|
||||
}
|
|
@ -53,7 +53,11 @@ namespace Bootstrap.Client
|
|||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||
options.Filters.Add<ExceptionFilter>();
|
||||
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.Cookie.Path = "/");
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
|
||||
{
|
||||
options.Cookie.Path = "/";
|
||||
options.RebuildRedirectUri(ConfigurationManager.AppSettings["AuthHost"]);
|
||||
});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
@{
|
||||
ViewBag.Title = "未授权请求";
|
||||
Layout = "_Root";
|
||||
}
|
||||
@section css {
|
||||
<link href="~/css/error.css" rel="stylesheet" asp-append-version="true" />
|
||||
}
|
||||
@section Javascript {
|
||||
<script src="~/js/error.js" asp-append-version="true"></script>
|
||||
}
|
||||
<section class="error-wrapper">
|
||||
<img src="~/images/error_icon.png" />
|
||||
<h1>网页拒绝访问</h1>
|
||||
<h3>您无权访问本页面请联系网站管理员授权后再查看</h3>
|
||||
<br />
|
||||
<a href="~/Home/Index" target="_top">返回首页</a>
|
||||
</section>
|
|
@ -34,7 +34,7 @@
|
|||
<a href="#"><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="@Model.LogoutUrl"><i class="fa fa-key"></i>注销</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue