bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
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
using System.Collections.Generic;
using System.Linq;
using Model;
using BLL;
using System.Web.Mvc;
namespace Lib
{
    public class LoginFilter : BaseAuthorizeAttribute
    {
        private bool ValidateLogin = true;
 
        private bool ValidateRequest = true;
 
        public LoginFilter()
            : base()
        {
 
        }
 
        public LoginFilter(bool _validateLogin)
            : base()
        {
            this.ValidateLogin = _validateLogin;
        }
 
        public LoginFilter(bool _validateLogin, bool _validateRequest)
            : base()
        {
            this.ValidateLogin = _validateLogin;
            this.ValidateRequest = _validateRequest;
        }
 
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (this.ValidateLogin)
            {
                UserInfo LoginUser = filterContext.HttpContext.Session["wms-session-userinfo"] as UserInfo;
                string path = filterContext.HttpContext.Request.Path;
                if (LoginUser == null)
                {
                    string url = "/Login/Login";
                    if (!string.IsNullOrEmpty(path))
                    {
                        path = filterContext.HttpContext.Server.UrlEncode(path);
                        url = url + "?returnurl=" + path;
                    }
                    filterContext.Result = new RedirectResult(url);
                }
                else
                {
                    if (ValidateRequest && path != "/")
                    {
                        if (!HasPower(path, LoginUser.UserCode))
                        {
                            string url = "/Home/Error";
                            filterContext.Result = new RedirectResult(url);
                        }
                    }
                }
            }
        }
 
        /// <summary>
        /// 判断是否有权限操作
        /// </summary>
        /// <param name="ResNum"></param>
        /// <param name="RoleNum"></param>
        /// <returns></returns>
        public bool HasPower(string ResNum, string RoleNum)
        {
            IDALGerUserMenu provider = new DALGetUserMenu();
            List<ResMenu> ListResult = provider.GetList(RoleNum).ToList();
            ListResult = ListResult == null? new List<ResMenu>() : ListResult;
            bool hasPower = ListResult.Exists(a => a.ResNum.ToLower() == ResNum.ToLower() || (a.Url != null && a.Url.ToLower() == ResNum.ToLower()));
            //超级管理员权限
            //if (RoleNum == "SuperUser" || RoleNum=="D001")//ResourceManager.GetSettingEntity("Super_AdminRole").Value
            //{
                hasPower = true;
            //}
            return hasPower;
        }
    }
}