From 0d0dd6d3efeff8e892071611490baed2a5303497 Mon Sep 17 00:00:00 2001 From: dathlin Date: Sun, 6 Aug 2017 20:36:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E6=88=B7=E6=9B=B4=E6=94=B9=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E5=88=9D=E6=AD=A5=E6=B7=BB=E5=8A=A0=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 63 +++++++++++++++++++ .../Models/Account/ModelAccount.cs | 21 +++++++ .../Views/Home/LackOfAuthority.cshtml | 14 +++++ .../Views/Home/ManagementAccount.cshtml | 6 +- .../Views/Home/RegisterAccount.cshtml | 55 ++++++++++++++++ 软件系统浏览器模版/软件系统浏览器模版.csproj | 2 + 6 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 软件系统浏览器模版/Views/Home/LackOfAuthority.cshtml create mode 100644 软件系统浏览器模版/Views/Home/RegisterAccount.cshtml diff --git a/软件系统浏览器模版/Controllers/HomeController.cs b/软件系统浏览器模版/Controllers/HomeController.cs index 974f08b..35ac8e4 100644 --- a/软件系统浏览器模版/Controllers/HomeController.cs +++ b/软件系统浏览器模版/Controllers/HomeController.cs @@ -35,6 +35,18 @@ namespace 软件系统浏览器模版.Controllers return View(); } + //Get + /// + /// 权限不足时显示的界面 + /// + /// + [AuthorizeUser] + public ActionResult LackOfAuthority() + { + return View(); + } + + /// /// 网站的联系人界面 /// @@ -184,5 +196,56 @@ namespace 软件系统浏览器模版.Controllers } return View(); } + + + //POST + /// + /// 设置新的账户的请求 + /// + /// + [HttpPost] + [AuthorizeUser] + [ValidateAntiForgeryToken] + public ActionResult SetManagementAccount(FormCollection fc) + { + if (Request.IsAjaxRequest()) + { + string Accounts = fc["NewAccounts"]; + UserAccount account = Session[SessionItemsDescription.UserAccount] as UserAccount; + + + OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.更细账户, Accounts); + if (result.IsSuccess) + { + ViewData["alertMessage"] = "账户更改成功!"; + return PartialView("_MessageSuccessPartial"); + } + else + { + ViewData["alertMessage"] = result.Message; + return PartialView("_MessageDangerPartial"); + } + } + else + { + ViewData["alertMessage"] = "请求无效!"; + return PartialView("_MessageDangerPartial"); + } + } + + + + + //GET + /// + /// 注册新的账户界面 + /// + [HttpGet] + [AuthorizeAdmin] + public ActionResult RegisterAccount() + { + return View(); + } + } } \ No newline at end of file diff --git a/软件系统浏览器模版/Models/Account/ModelAccount.cs b/软件系统浏览器模版/Models/Account/ModelAccount.cs index 224bae9..008cf4f 100644 --- a/软件系统浏览器模版/Models/Account/ModelAccount.cs +++ b/软件系统浏览器模版/Models/Account/ModelAccount.cs @@ -29,4 +29,25 @@ namespace 软件系统浏览器模版.Models.Account } } } + + /// + /// 验证系统的账户是否符合管理员的信息 + /// + public class AuthorizeAdminAttribute : AuthorizeAttribute + { + public override void OnAuthorization(AuthorizationContext filterContext) + { + if (filterContext.HttpContext.Session[SessionItemsDescription.UserAccount] is UserAccount account) + { + if (account.Grade < AccountGrade.SuperAdministrator) + { + filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Home", action = "LackOfAuthority" })); + } + } + else + { + filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Login" })); + } + } + } } \ No newline at end of file diff --git a/软件系统浏览器模版/Views/Home/LackOfAuthority.cshtml b/软件系统浏览器模版/Views/Home/LackOfAuthority.cshtml new file mode 100644 index 0000000..1753d1d --- /dev/null +++ b/软件系统浏览器模版/Views/Home/LackOfAuthority.cshtml @@ -0,0 +1,14 @@ + +@{ + ViewBag.Title = "权限不足"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + + + +
+ +

错误信息

+

非常抱歉,您的权限不足,无法进行操作!

+
+ diff --git a/软件系统浏览器模版/Views/Home/ManagementAccount.cshtml b/软件系统浏览器模版/Views/Home/ManagementAccount.cshtml index 03d0d9a..4df1f0e 100644 --- a/软件系统浏览器模版/Views/Home/ManagementAccount.cshtml +++ b/软件系统浏览器模版/Views/Home/ManagementAccount.cshtml @@ -13,16 +13,16 @@
@{ string updateId = Guid.NewGuid().ToString();} - @using (Ajax.BeginForm("SetAnnouncement", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = updateId, InsertionMode = InsertionMode.Replace }, + @using (Ajax.BeginForm("SetManagementAccount", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = updateId, InsertionMode = InsertionMode.Replace }, new { @class = "form-horizontal" })) {
@Html.AntiForgeryToken() 账户管理
- +
- +
diff --git a/软件系统浏览器模版/Views/Home/RegisterAccount.cshtml b/软件系统浏览器模版/Views/Home/RegisterAccount.cshtml new file mode 100644 index 0000000..2a0c64f --- /dev/null +++ b/软件系统浏览器模版/Views/Home/RegisterAccount.cshtml @@ -0,0 +1,55 @@ + +@{ + ViewBag.Title = "注册新的账户"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + + + +@section scripts +{ + +} + +
+ +
+ @{ string updateId = Guid.NewGuid().ToString();} + @using (Ajax.BeginForm("RegisterAccount", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = updateId, InsertionMode = InsertionMode.Replace }, + new { @class = "form-horizontal" })) + { +
+ @Html.AntiForgeryToken() + 注册新的账户如果账户名已存在,会注册失败 + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+
+
+ } +
+
+ +
diff --git a/软件系统浏览器模版/软件系统浏览器模版.csproj b/软件系统浏览器模版/软件系统浏览器模版.csproj index 1894bb4..7f3a702 100644 --- a/软件系统浏览器模版/软件系统浏览器模版.csproj +++ b/软件系统浏览器模版/软件系统浏览器模版.csproj @@ -228,6 +228,8 @@ + +