Ejemplo n.º 1
0
        /// <summary>
        ///  登陆获取用户信息
        /// </summary>
        /// <param name="loginName"></param>
        public static void LogIn(string loginName, UserInfo user)
        {
            string url    = ConfigurationManager.AppSettings["ArasUrl"];
            string dbName = ConfigurationManager.AppSettings["ArasDB"];

            //获取用户信息
            USER userObJ = UserDA.GetUserByLoginName(loginName);

            if (userObJ != null)
            {
                user.UserId      = userObJ.ID;
                user.UserName    = userObJ.KEYED_NAME;
                user.LoginName   = userObJ.LOGIN_NAME;
                user.Password    = userObJ.PASSWORD;
                user.b_JobNumber = userObJ.B_JOBNUMBER;
                user.Email       = userObJ.EMAIL;
                HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, dbName, user.LoginName, user.Password);
                Item login_result         = conn.Login();
                if (login_result.isError())
                {
                    if (conn != null)
                    {
                        conn.Logout();
                    }
                }
                else
                {
                    var inn = login_result.getInnovator();
                    if (inn != null)
                    {
                        //获取当前角色身份
                        List <string> listRoles = IdentityDA.getIdentityListByUserID(inn, user.UserId);
                        user.Roles = listRoles;

                        if ((user.AgentAuth == null && user.AgentCreateTime == null) || (user.AgentCreateTime != null))
                        {
                            List <AgentSetEntity> AgentSetList = AgentSetBll.GetAgentSetByUserName(user.UserName);
                            if (AgentSetList.Count > 0)
                            {
                                AgentSetBll.GetAgentRoles(inn, user, AgentSetList);
                            }
                        }
                        user.inn = inn;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取委托的权限信息
        /// </summary>
        /// <param name="UserName">用户名称</param>
        /// <param name="moduleName">模块名称</param>
        public static void GetAgentRoles(Innovator inn, UserInfo Userinfo, List <AgentSetEntity> list, string moduleName = "")
        {
            //判断当前该模块的委托信息是否已经获取
            //List<string> agentRoles = new List<string>();
            List <AgentAuthEntity> AgentAuthList = new List <AgentAuthEntity>();

            //var list = GetAgentSetByUserName(Userinfo.UserName, moduleName);
            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    AgentAuthEntity agentAuth = new AgentAuthEntity();
                    //根据名称查询用户
                    USER          user      = UserDA.GetUserByFirstName(item.b_DelegateName);
                    List <string> listRoles = IdentityDA.getIdentityListByUserID(inn, user.ID);
                    //agentRoles.AddRange(listRoles);
                    agentAuth.delegateName = item.b_DelegateName;
                    agentAuth.agentRoles   = listRoles;
                    if (!string.IsNullOrEmpty(item.b_AgentContent))
                    {
                        agentAuth.moduleNames = item.b_AgentContent.Split(';').Where(x => x != "").ToList();
                    }
                    if (AgentAuthList.Where(x => x.delegateName == agentAuth.delegateName).ToList().Count == 0)
                    {
                        AgentAuthList.Add(agentAuth);
                    }
                }
                //将数据插入缓存
                Userinfo.AgentAuth       = AgentAuthList;
                Userinfo.AgentCreateTime = DateTime.Now;
                //MemoryCacheUtils.Clear(Userinfo.LoginName);
                //CacheItemPolicy policy = new CacheItemPolicy();
                //policy.Priority = CacheItemPriority.NotRemovable;
                //MemoryCacheUtils.Set(Userinfo.LoginName, Userinfo, policy);
            }
            //return agentRoles;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 登入(Login)
        /// </summary>
        /// <param name="pUrl">URL</param>
        /// <param name="pDBName">DBName</param>
        /// <param name="pUserName">UserName</param>
        /// <param name="pPassword">Password</param>
        /// <returns></returns>
        public ActionResult LogIn()
        {
            //判断当前系统语言
            string language = Request.Headers["Accept-Language"].ToString();

            language = language.Split(',')[0].ToString();
            if (language.IndexOf("en") >= 0)
            {
                language = "English";
            }
            else
            {
                language = "Chinese";
            }

            string url        = ConfigurationManager.AppSettings["ArasUrl"];
            string dbName     = ConfigurationManager.AppSettings["ArasDB"];
            string username   = Request.Form["Username"];
            string password   = Request.Form["Password"];
            string ChoicePath = Request.Form["ChoicePath"];
            string str        = "";

            try
            {
                //string DomainKey = "admin";
                //string ForceSha = "0";
                //string passwordStr = CommonMethod.md5string16(DomainKey, ForceSha == "1" ? true : false) + CommonMethod.md5string16(username.ToLower(), ForceSha == "1" ? true : false) + username.ToLower() + DomainKey;
                //HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, dbName, username, password);
                //Item login_result = conn.Login();
                //if (login_result.isError())
                //{
                //}
                //strPassword = md5string16(DomainKey, IIf(ForceSha = "1", True, False)) + md5string16(strUserName.ToLower(), IIf(ForceSha = "1", True, False)) + strUserName.ToLower() + DomainKey 参考代码
                UserInfo user     = new UserInfo();
                string   errorMsg = "";
                //if (username == "admin")
                //{
                //    HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, dbName, username, password);
                //    Item login_result = conn.Login();
                //    if (login_result.isError())
                //    {
                //        if (conn != null) { conn.Logout(); }
                //        str = login_result.getErrorString();
                //        int startIndex = (str.IndexOf(":") + 1);
                //        if (startIndex > 0) { str = str.Substring(startIndex); }
                //        if (str.Contains("Authentication")) { str = "Invalid user or password"; }
                //    }
                //    else
                //    {
                //        errorMsg = "AD Login OK";
                //    }
                //}
                //else
                //{
                //    errorMsg = LoginAD(username, password);
                //}
                errorMsg = "AD Login OK";
                if (errorMsg == "AD Login OK")
                {
                    //获取用户信息
                    USER userObJ = UserDA.GetUserByLoginName(username);
                    // 创建登录凭证

                    user.UserId              = userObJ.ID;
                    user.UserName            = userObJ.KEYED_NAME;
                    user.LoginName           = userObJ.LOGIN_NAME;
                    user.Password            = userObJ.PASSWORD;
                    user.HTTP_USER_AGENT     = Request.UserAgent;
                    user.UserIp              = Request.UserHostAddress;
                    user.b_JobNumber         = userObJ.B_JOBNUMBER;
                    user.Email               = userObJ.EMAIL;
                    user.language            = language;
                    user.b_AffiliatedCompany = userObJ.B_AFFILIATEDCOMPANY;

                    //获取AD域中的信息
                    CommonMethod.GetAdInfoByUser(user, "bordrin.com");

                    user.ExpireDate = DateTime.Now.AddDays(1);
                    //Innovator.ScalcMD5(user.Password)
                    HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, dbName, user.LoginName, user.Password);
                    Item login_result         = conn.Login();
                    if (login_result.isError())
                    {
                        if (conn != null)
                        {
                            conn.Logout();
                        }
                        str = login_result.getErrorString();
                        int startIndex = (str.IndexOf(":") + 1);
                        if (startIndex > 0)
                        {
                            str = str.Substring(startIndex);
                        }
                        if (str.Contains("Authentication"))
                        {
                            str = "Invalid user or password";
                        }
                    }
                    else
                    {
                        var inn = login_result.getInnovator();
                        //string token = Guid.NewGuid().ToString("N").ToUpper();
                        //获取当前角色身份
                        List <string> listRoles = IdentityDA.getIdentityListByUserID(inn, user.UserId);
                        user.Roles = listRoles;
                        //获取当前权限信息
                        if (user.MemuAuth == null)
                        {
                            user.MemuAuth = new List <string>();
                            for (int j = 0; j < listRoles.Count; j++)
                            {
                                string id = listRoles[j];
                                //根据Id获取权限列表
                                Item ItemTypes = ItemTypeDA.GetMenuAuthByIdentity(inn, id);
                                if (ItemTypes.getItemCount() > 0)
                                {
                                    for (int i = 0; i < ItemTypes.getItemCount(); i++)
                                    {
                                        Item   itemobj  = ItemTypes.getItemByIndex(i);
                                        string itemName = itemobj.getProperty("name");
                                        if (user.MemuAuth.IndexOf(itemName) < 0)
                                        {
                                            user.MemuAuth.Add(itemName);
                                        }
                                    }
                                }
                            }
                        }
                        user.inn = inn;

                        //获取委托的权限数据
                        DateTime currentTime = DateTime.Now.AddMinutes(-10);
                        if ((user.AgentAuth == null && user.AgentCreateTime == null) || (user.AgentCreateTime != null && currentTime > user.AgentCreateTime))
                        {
                            List <AgentSetEntity> AgentSetList = AgentSetBll.GetAgentSetByUserName(user.UserName);
                            if (AgentSetList.Count > 0)
                            {
                                AgentSetBll.GetAgentRoles(inn, user, AgentSetList);
                            }
                        }


                        UserBll.SaveUserInfoToCache(user);
                        // 设置用户 cookie
                        HttpCookie cookie = new HttpCookie("Passport.Token");
                        cookie.Value   = user.LoginName;
                        cookie.Expires = DateTime.Now.AddHours(8);
                        cookie.Secure  = FormsAuthentication.RequireSSL;
                        Response.Cookies.Add(cookie);
                        if (ChoicePath == "0")
                        {
                            return(Redirect("/Portal/Index"));
                        }
                        else
                        {
                            return(Redirect("/Home/Index"));
                        }
                    }
                }
                else
                {
                    str = "Invalid user or password";
                }
            }
            catch (Exception ex)
            {
                str = "Invalid user or password";
            }
            return(RedirectToAction("Index", "Login", new { errorStr = str, isAdLogin = false }));
        }
Ejemplo n.º 4
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpCookie cookie = HttpContext.Request.Cookies["Passport.Token"];

            if (cookie == null) // 站内凭证不存在
            {
                Response.Redirect("/Login/Index");
            }
            else
            {
                if (Userinfo == null || Userinfo.LoginName != cookie.Value)
                {
                    //string language = Request.Headers["Accept-Language"].ToString();
                    //language = language.Split(',')[0].ToString();
                    Userinfo = UserBll.GetUserInfoByUserName(cookie.Value);

                    if (Userinfo == null)
                    {
                        Response.Redirect("/Login/Index");
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(Userinfo.department))
                        {
                            CommonMethod.GetAdInfoByUser(Userinfo, "bordrin.com");
                        }
                        ViewBag.userName = Userinfo.UserName;
                        ViewBag.language = Userinfo.language;
                    }

                    bool isaddCache = false;

                    inn = Userinfo.inn;
                    if (inn == null || inn.getUserID() != Userinfo.UserId)
                    {
                        using (ArasInnovator arasConn = new ArasInnovator())
                        {
                            inn          = arasConn.ArasConnection(Userinfo.LoginName, Userinfo.Password);
                            Userinfo.inn = inn;
                            isaddCache   = true;
                        }
                    }


                    //如果角色为空,获取角色权限
                    if (Userinfo.Roles == null)
                    {
                        Userinfo.Roles = IdentityDA.getIdentityListByUserID(inn, Userinfo.UserId);
                        isaddCache     = true;
                    }

                    //如果菜单权限为空,获取菜单权限
                    if (Userinfo.MemuAuth == null)
                    {
                        Userinfo.MemuAuth = new List <string>();
                        for (int j = 0; j < Userinfo.Roles.Count; j++)
                        {
                            string id = Userinfo.Roles[j];
                            //根据Id获取权限列表
                            Item ItemTypes = ItemTypeDA.GetMenuAuthByIdentity(inn, id);
                            if (ItemTypes.getItemCount() > 0)
                            {
                                for (int i = 0; i < ItemTypes.getItemCount(); i++)
                                {
                                    Item   itemobj  = ItemTypes.getItemByIndex(i);
                                    string itemName = itemobj.getProperty("name");
                                    if (Userinfo.MemuAuth.IndexOf(itemName) < 0)
                                    {
                                        Userinfo.MemuAuth.Add(itemName);
                                    }
                                }
                            }
                        }
                        isaddCache = true;
                    }

                    //获取委托的权限数据
                    DateTime currentTime = DateTime.Now.AddMinutes(-10);
                    if ((Userinfo.AgentAuth == null && Userinfo.AgentCreateTime == null) || (Userinfo.AgentCreateTime != null && currentTime > Userinfo.AgentCreateTime))
                    {
                        List <AgentSetEntity> AgentSetList = AgentSetBll.GetAgentSetByUserName(Userinfo.UserName);
                        if (AgentSetList.Count > 0)
                        {
                            AgentSetBll.GetAgentRoles(inn, Userinfo, AgentSetList);
                            isaddCache = true;
                        }
                    }

                    //重新添加缓存
                    if (isaddCache)
                    {
                        CacheItemPolicy policy = new CacheItemPolicy();
                        policy.Priority = CacheItemPriority.NotRemovable;
                        MemoryCacheUtils.Set(Userinfo.LoginName, Userinfo, policy);
                    }
                }
                else
                {
                    ViewBag.userName = Userinfo.UserName;
                    ViewBag.language = Userinfo.language;
                }

                ViewData["MemuAuth"] = Userinfo.MemuAuth;
                string strController = filterContext.RouteData.Values["controller"].ToString();
                switch (strController)
                {
                case "MenuAuthManage":
                    string menuAuthManage = Userinfo.MemuAuth.Where(x => x == "b_MenuAuthManage").FirstOrDefault();
                    if (string.IsNullOrEmpty(menuAuthManage))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "RoleManage":
                    string roleManage = Userinfo.MemuAuth.Where(x => x == "b_RoleManage").FirstOrDefault();
                    if (string.IsNullOrEmpty(roleManage))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "ProjectManage":
                    string projectManage = Userinfo.MemuAuth.Where(x => x == "b_ProjectManage").FirstOrDefault();
                    if (string.IsNullOrEmpty(projectManage))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "OrganizationalStructure":
                    string organizationalStructure = Userinfo.MemuAuth.Where(x => x == "b_OrganizationalStructure").FirstOrDefault();
                    if (string.IsNullOrEmpty(organizationalStructure))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "User":
                    string user = Userinfo.MemuAuth.Where(x => x == "b_User").FirstOrDefault();
                    if (string.IsNullOrEmpty(user))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "ExpenseCategory":
                    string expenseCategory = Userinfo.MemuAuth.Where(x => x == "b_ExpenseCategory").FirstOrDefault();
                    if (string.IsNullOrEmpty(expenseCategory))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "ExpenseAuditConfiguration":
                    string expenseAuditConfiguration = Userinfo.MemuAuth.Where(x => x == "b_ExpenseAuditConfiguration").FirstOrDefault();
                    if (string.IsNullOrEmpty(expenseAuditConfiguration))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                case "AgentSet":
                    string agentSet = Userinfo.MemuAuth.Where(x => x == "b_AgentSet").FirstOrDefault();
                    if (string.IsNullOrEmpty(agentSet))
                    {
                        Response.Redirect("/Home/AuthWarn");
                    }
                    break;

                default:
                    break;
                }
            }
            base.OnActionExecuting(filterContext);
        }