jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
    }
}