完成登录窗体及权限验证的设计
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 网站的主界面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AuthorizeUser]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 网站的关于界面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AuthorizeUser]
|
||||
public ActionResult About()
|
||||
{
|
||||
ViewBag.Message = "Your application description page.";
|
||||
@@ -20,6 +32,11 @@ namespace 软件系统浏览器模版.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网站的联系人界面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AuthorizeUser]
|
||||
public ActionResult Contact()
|
||||
{
|
||||
ViewBag.Message = "Your contact page.";
|
||||
|
||||
32
软件系统浏览器模版/Models/Account/ModelAccount.cs
Normal file
32
软件系统浏览器模版/Models/Account/ModelAccount.cs
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证系统是否登录成功的特性
|
||||
/// </summary>
|
||||
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" }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
软件系统浏览器模版/Models/ModelBase.cs
Normal file
40
软件系统浏览器模版/Models/ModelBase.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace 软件系统浏览器模版.Models
|
||||
{
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
*
|
||||
* 基础的数据核心
|
||||
*
|
||||
***********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public class ModelBase
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Session的数据集合的描述
|
||||
/// </summary>
|
||||
public class SessionItemsDescription
|
||||
{
|
||||
public static string UserAccount { get; set; } = "SoftUserAccount";
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { @class = "form-horizontal" }))
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
<span class="heading">XX管理系统<small style="font-family:'Microsoft YaHei';color:#a1a1a1;font-size:15px">用户登录</small></span>
|
||||
<span class="heading">@CommonLibrary.Resource.StringResouce.SoftName<small style="font-family:'Microsoft YaHei';color:#a1a1a1;font-size:15px">用户登录</small></span>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" name="UserName" placeholder="用户名" required>
|
||||
<i class="fa fa-user"></i>
|
||||
|
||||
@@ -157,6 +157,8 @@
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\Account\ModelAccount.cs" />
|
||||
<Compile Include="Models\ModelBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -215,7 +217,6 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Images\Shared\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user