using HH.AutoBom.Common;
|
using HH.Employee.Redis.ReisModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Web;
|
using System.Web.Mvc;
|
|
namespace HH.AutoBom.WebUI.AppCode
|
{
|
|
public class BasePage : Controller
|
{
|
|
//[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
|
//public class AuthorizeFilterAttribute : ActionFilterAttribute
|
//{
|
// public override void OnActionExecuting(ActionExecutingContext filterContext)
|
// {
|
// /*
|
// 判断是否已经登录
|
// */
|
// }
|
//}
|
|
public BasePage()
|
{
|
if (Request != null)
|
{
|
//获得cookie(登录名)
|
HttpCookie ck_login = Request.Cookies[Constants.cookie_username];
|
string login = ck_login.Value;
|
|
//获得cookie(随机码)
|
HttpCookie ck_flag = Request.Cookies[Constants.cookie_flag];
|
string flag = ck_flag.Value;
|
|
string appCode = Constants.appCode;
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(flag) || string.IsNullOrEmpty(appCode))
|
{
|
Response.Redirect("~/Login");
|
}
|
else
|
{
|
try
|
{
|
RedisUserInfo userInfo = UserInfoFactory.CreateCurrent(Login, Flag, AppCode);
|
if (userInfo == null || string.IsNullOrEmpty(userInfo.CN_S_LOGIN) || userInfo.CN_S_FLAG != Flag)
|
{
|
Response.Redirect("~/Login");
|
}
|
}
|
catch { Response.Redirect("~/Login"); }
|
}
|
}
|
}
|
|
private RedisUserInfo userInfo;
|
/// <summary>
|
/// 登录用户信息
|
/// </summary>
|
public RedisUserInfo LoginUser
|
{
|
get
|
{
|
if (userInfo == null)
|
{
|
//使用redis保存用户信息
|
userInfo = UserInfoFactory.CreateCurrent(Login, Flag, AppCode);
|
}
|
return userInfo;
|
}
|
}
|
|
#region 用户名
|
/// <summary>
|
/// 用户名
|
/// </summary>
|
public string Login
|
{
|
get
|
{
|
return Request.Cookies[Constants.cookie_username].Value;
|
}
|
}
|
#endregion
|
|
#region 用户标识
|
/// <summary>
|
/// 用户标识
|
/// </summary>
|
public string Flag
|
{
|
get
|
{
|
return Request.Cookies[Constants.cookie_flag].Value;
|
}
|
}
|
#endregion
|
|
#region 应用ID
|
/// <summary>
|
/// 应用ID
|
/// </summary>
|
public string AppCode
|
{
|
get
|
{
|
return Constants.appCode;
|
}
|
}
|
#endregion
|
}
|
}
|