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