From e359f472f39f11ae762ab8d674740321e862da5e Mon Sep 17 00:00:00 2001 From: dathlin Date: Sun, 23 Jul 2017 20:06:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=99=BB=E5=BD=95=E7=AA=97?= =?UTF-8?q?=E4=BD=93=E5=8F=8A=E6=9D=83=E9=99=90=E9=AA=8C=E8=AF=81=E7=9A=84?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 12 ++++-- .../Controllers/HomeController.cs | 17 ++++++++ .../Models/Account/ModelAccount.cs | 32 +++++++++++++++ 软件系统浏览器模版/Models/ModelBase.cs | 40 +++++++++++++++++++ 软件系统浏览器模版/Views/Account/Login.cshtml | 2 +- 软件系统浏览器模版/软件系统浏览器模版.csproj | 3 +- 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 软件系统浏览器模版/Models/Account/ModelAccount.cs create mode 100644 软件系统浏览器模版/Models/ModelBase.cs diff --git a/软件系统浏览器模版/Controllers/AccountController.cs b/软件系统浏览器模版/Controllers/AccountController.cs index 8debbdb..36c64bf 100644 --- a/软件系统浏览器模版/Controllers/AccountController.cs +++ b/软件系统浏览器模版/Controllers/AccountController.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using 软件系统浏览器模版.Models; namespace 软件系统浏览器模版.Controllers { @@ -68,7 +69,8 @@ namespace 软件系统浏览器模版.Controllers //不允许登录 return Login(account.ForbidMessage); } - UserClient.UserAccount = account; + Session[SessionItemsDescription.UserAccount] = account; + //UserClient.UserAccount = account; } else { @@ -87,14 +89,14 @@ namespace 软件系统浏览器模版.Controllers { if (UserClient.CurrentVersion != sv) { - return Login("当前版本号不正确,需要服务器更新才允许登录。"); + return Login("当前版本号不正确,需要联系管理员更新服务器才允许登录。"); } } else { if (UserClient.CurrentVersion < sv) { - return Login("版本号过时,需要管理员更新才允许登录。"); + return Login("版本号过时,需要联系管理员更新服务器才允许登录。"); } } } @@ -107,5 +109,9 @@ namespace 软件系统浏览器模版.Controllers //允许登录,并记录到Session return RedirectToAction("Index", "Home"); } + + + + } } \ No newline at end of file diff --git a/软件系统浏览器模版/Controllers/HomeController.cs b/软件系统浏览器模版/Controllers/HomeController.cs index c3c5c99..3f145a2 100644 --- a/软件系统浏览器模版/Controllers/HomeController.cs +++ b/软件系统浏览器模版/Controllers/HomeController.cs @@ -3,16 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using 软件系统浏览器模版.Models.Account; namespace 软件系统浏览器模版.Controllers { public class HomeController : Controller { + /// + /// 网站的主界面 + /// + /// + [AuthorizeUser] public ActionResult Index() { return View(); } + + /// + /// 网站的关于界面 + /// + /// + [AuthorizeUser] public ActionResult About() { ViewBag.Message = "Your application description page."; @@ -20,6 +32,11 @@ namespace 软件系统浏览器模版.Controllers return View(); } + /// + /// 网站的联系人界面 + /// + /// + [AuthorizeUser] public ActionResult Contact() { ViewBag.Message = "Your contact page."; diff --git a/软件系统浏览器模版/Models/Account/ModelAccount.cs b/软件系统浏览器模版/Models/Account/ModelAccount.cs new file mode 100644 index 0000000..224bae9 --- /dev/null +++ b/软件系统浏览器模版/Models/Account/ModelAccount.cs @@ -0,0 +1,32 @@ +using CommonLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; + +namespace 软件系统浏览器模版.Models.Account +{ + public class ModelAccount + { + } + + /// + /// 验证系统是否登录成功的特性 + /// + public class AuthorizeUserAttribute : AuthorizeAttribute + { + public override void OnAuthorization(AuthorizationContext filterContext) + { + if ((filterContext.HttpContext.Session[SessionItemsDescription.UserAccount] as UserAccount) != null) + { + //授权成功 + } + else + { + filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Login" })); + } + } + } +} \ No newline at end of file diff --git a/软件系统浏览器模版/Models/ModelBase.cs b/软件系统浏览器模版/Models/ModelBase.cs new file mode 100644 index 0000000..3137221 --- /dev/null +++ b/软件系统浏览器模版/Models/ModelBase.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace 软件系统浏览器模版.Models +{ + + + /*********************************************************************************** + * + * 基础的数据核心 + * + ***********************************************************************************/ + + + + + public class ModelBase + { + + + } + + + + + + + + + + /// + /// Session的数据集合的描述 + /// + public class SessionItemsDescription + { + public static string UserAccount { get; set; } = "SoftUserAccount"; + } +} \ No newline at end of file diff --git a/软件系统浏览器模版/Views/Account/Login.cshtml b/软件系统浏览器模版/Views/Account/Login.cshtml index 5697c6c..39a7172 100644 --- a/软件系统浏览器模版/Views/Account/Login.cshtml +++ b/软件系统浏览器模版/Views/Account/Login.cshtml @@ -21,7 +21,7 @@ @using (Html.BeginForm("Login", "Account", FormMethod.Post, new { @class = "form-horizontal" })) { @Html.AntiForgeryToken() - XX管理系统用户登录 + @CommonLibrary.Resource.StringResouce.SoftName用户登录
diff --git a/软件系统浏览器模版/软件系统浏览器模版.csproj b/软件系统浏览器模版/软件系统浏览器模版.csproj index a1f0253..cf06cf8 100644 --- a/软件系统浏览器模版/软件系统浏览器模版.csproj +++ b/软件系统浏览器模版/软件系统浏览器模版.csproj @@ -157,6 +157,8 @@ Global.asax + + @@ -215,7 +217,6 @@ -