From 7c49d36ebbc534080aa084910ea7538453c49807 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Wed, 10 Oct 2018 12:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E5=88=A0=E9=99=A4AccountController=EF=BC=8C=E4=BD=BF=E7=94=A8B?= =?UTF-8?q?A=E5=90=8E=E5=8F=B0=E7=9A=84=E7=99=BB=E5=BD=95/=E7=99=BB?= =?UTF-8?q?=E5=87=BA/=E6=9D=83=E9=99=90=E6=8B=92=E7=BB=9D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 44 ------------------- Bootstrap.Client/Models/HeaderBarModel.cs | 12 ++++- Bootstrap.Client/Models/ModelBase.cs | 4 +- Bootstrap.Client/Models/NavigatorBarModel.cs | 2 +- Bootstrap.Client/Startup.cs | 6 ++- .../Views/Shared/AccessDenied.cshtml | 17 ------- Bootstrap.Client/Views/Shared/Header.cshtml | 2 +- 7 files changed, 19 insertions(+), 68 deletions(-) delete mode 100644 Bootstrap.Client/Controllers/AccountController.cs delete mode 100644 Bootstrap.Client/Views/Shared/AccessDenied.cshtml diff --git a/Bootstrap.Client/Controllers/AccountController.cs b/Bootstrap.Client/Controllers/AccountController.cs deleted file mode 100644 index 51e4ed26..00000000 --- a/Bootstrap.Client/Controllers/AccountController.cs +++ /dev/null @@ -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 -{ - /// - /// Account controller. - /// - [AllowAnonymous] - public class AccountController : Controller - { - /// - /// - /// - /// - 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}"); - } - /// - /// Logout this instance. - /// - /// The logout. - public IActionResult Logout() - { - return Redirect($"{ConfigurationManager.AppSettings["AuthHost"]}{CookieAuthenticationDefaults.LogoutPath}"); - } - /// - /// Accesses the denied. - /// - /// The denied. - [ResponseCache(Duration = 600)] - public ActionResult AccessDenied() - { - return View(); - } - } -} \ No newline at end of file diff --git a/Bootstrap.Client/Models/HeaderBarModel.cs b/Bootstrap.Client/Models/HeaderBarModel.cs index 40f7b006..42d5995c 100644 --- a/Bootstrap.Client/Models/HeaderBarModel.cs +++ b/Bootstrap.Client/Models/HeaderBarModel.cs @@ -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; } /// @@ -39,10 +43,14 @@ namespace Bootstrap.Client.Models /// /// 获得/设置 设置网址 /// - public string SettingsUrl { get; set; } + public string SettingsUrl { get; } /// /// 获得/设置 个人中心网址 /// - public string ProfilesUrl { get; set; } + public string ProfilesUrl { get; } + /// + /// 获得 退出登录地址 + /// + public string LogoutUrl { get; set; } } } \ No newline at end of file diff --git a/Bootstrap.Client/Models/ModelBase.cs b/Bootstrap.Client/Models/ModelBase.cs index 9a1a7293..f7d53c40 100644 --- a/Bootstrap.Client/Models/ModelBase.cs +++ b/Bootstrap.Client/Models/ModelBase.cs @@ -19,11 +19,11 @@ namespace Bootstrap.Client.Models /// /// /// - public string Title { get; private set; } + public string Title { get; } /// /// /// - public string Footer { get; private set; } + public string Footer { get; } /// /// /// diff --git a/Bootstrap.Client/Models/NavigatorBarModel.cs b/Bootstrap.Client/Models/NavigatorBarModel.cs index e50d0ae7..0474f05e 100644 --- a/Bootstrap.Client/Models/NavigatorBarModel.cs +++ b/Bootstrap.Client/Models/NavigatorBarModel.cs @@ -20,6 +20,6 @@ namespace Bootstrap.Client.Models /// /// /// - public IEnumerable Navigations { get; private set; } + public IEnumerable Navigations { get;} } } \ No newline at end of file diff --git a/Bootstrap.Client/Startup.cs b/Bootstrap.Client/Startup.cs index 0647a124..65ea1491 100644 --- a/Bootstrap.Client/Startup.cs +++ b/Bootstrap.Client/Startup.cs @@ -53,7 +53,11 @@ namespace Bootstrap.Client options.Filters.Add(); options.Filters.Add(); }).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. diff --git a/Bootstrap.Client/Views/Shared/AccessDenied.cshtml b/Bootstrap.Client/Views/Shared/AccessDenied.cshtml deleted file mode 100644 index 15fa6c3f..00000000 --- a/Bootstrap.Client/Views/Shared/AccessDenied.cshtml +++ /dev/null @@ -1,17 +0,0 @@ -@{ - ViewBag.Title = "未授权请求"; - Layout = "_Root"; -} -@section css { - -} -@section Javascript { - -} -
- -

网页拒绝访问

-

您无权访问本页面请联系网站管理员授权后再查看

-
- 返回首页 -
\ No newline at end of file diff --git a/Bootstrap.Client/Views/Shared/Header.cshtml b/Bootstrap.Client/Views/Shared/Header.cshtml index 41f4074f..a91e1c72 100644 --- a/Bootstrap.Client/Views/Shared/Header.cshtml +++ b/Bootstrap.Client/Views/Shared/Header.cshtml @@ -34,7 +34,7 @@ 通知