Exemple #1
0
        /// <summary>
        /// 获取菜单权限根据帐号
        /// </summary>
        /// <returns></returns>
        public JsonResult GetMenuAuthByIdentity(string id)
        {
            var retModel = new JsonReturnModel();

            try
            {
                List <string> list = new List <string>();

                MenuAuthManageModel model = new MenuAuthManageModel();
                Item Identity             = IdentityDA.GetIdentityById(inn, id);
                if (Identity.getItemCount() > 0)
                {
                    model.Id         = Identity.getProperty("id");
                    model.Is_Alias   = Identity.getProperty("is_alias");
                    model.KEYED_NAME = Identity.getProperty("keyed_name");
                    Item result = ItemTypeDA.GetMenuAuthByIdentity(inn, id);
                    if (result.getItemCount() > 0)
                    {
                        for (int index = 0; index < result.getItemCount(); index++)
                        {
                            Item   item       = result.getItemByIndex(index);
                            string keyed_name = item.getProperty("keyed_name");
                            list.Add(keyed_name);
                        }
                    }
                    model.AuthList = list;
                }
                retModel.data = model;
            }
            catch (Exception ex)
            {
                retModel.AddError("errorMessage", ex.Message);
            }
            return(Json(retModel, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        /// <summary>
        /// 获取列表信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetIdentityList(DataTableParameter para, string searchValue)
        {
            int total = 0;
            List <MenuAuthManageModel> list = new List <MenuAuthManageModel>();
            var dataList = IdentityDA.GetIdentityList(out total, para, searchValue);

            if (dataList != null)
            {
                for (int index = 0; index < dataList.Count(); index++)
                {
                    MenuAuthManageModel model = new MenuAuthManageModel();
                    var    item      = dataList[index];
                    string strHtml   = "<div class='row'><div class='col-md-8'>{0}</div><div class='col-md-4' style='text-align:right'>{1}</div></div>";
                    string linkAList = "<a class='glyphicon glyphicon-cog configMemuAuth' title='配置'  Id='" + item.ID + "' ></a>";
                    strHtml          = string.Format(strHtml, item.KEYED_NAME, linkAList);
                    model.Id         = item.ID;
                    model.KEYED_NAME = strHtml;
                    model.AuthStr    = "";
                    Item Items = ItemTypeDA.GetMenuAuthByIdentity(inn, item.ID);
                    if (Items.getItemCount() > 0)
                    {
                        for (int i = 0; i < Items.getItemCount(); i++)
                        {
                            Item   obj   = Items.getItemByIndex(i);
                            string lable = obj.getProperty("name");
                            model.AuthStr += lable + ";";
                        }
                    }
                    list.Add(model);
                }
            }


            return(Json(new
            {
                sEcho = para.sEcho,
                iTotalRecords = total,
                iTotalDisplayRecords = total,
                aaData = list
            }, JsonRequestBehavior.AllowGet));
        }
        /// <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 }));
        }
Exemple #4
0
        /// <summary>
        /// 保存菜单权限
        /// </summary>
        /// <returns></returns>
        public JsonResult SaveMenuAuth(MenuAuthManageModel model)
        {
            var retModel = new JsonReturnModel();

            try
            {
                Item   result;
                string amlStr = "";
                Item   item   = ItemTypeDA.GetMenuAuthByIdentity(inn, model.Id);
                //删除已经有的
                if (item.getItemCount() > 0)
                {
                    for (int i = 0; i < item.getItemCount(); i++)
                    {
                        var    itemObj   = item.getItemByIndex(i);
                        string keyedName = itemObj.getProperty("keyed_name");
                        string value     = "";
                        if (model.AuthList != null)
                        {
                            value = model.AuthList.Where(x => x == keyedName.Trim()).FirstOrDefault();
                        }
                        if (string.IsNullOrEmpty(value))
                        {
                            string typeId = itemObj.getProperty("id");
                            //获取关系类TOC_ACCESS对象
                            Item   Relation = itemObj.getRelationships();
                            string tocId    = "";
                            for (int k = 0; k < Relation.getItemCount(); k++)
                            {
                                Item   relationObJ = Relation.getItemByIndex(k);
                                string name        = relationObJ.getRelatedItem().getProperty("name");
                                if (name == model.KEYED_NAME)
                                {
                                    tocId = relationObJ.getProperty("id");
                                }
                            }
                            if (!string.IsNullOrEmpty(typeId) && !string.IsNullOrEmpty(tocId))
                            {
                                amlStr += "<Item type='ITEMTYPE' action='edit' id='" + typeId + "'><Relationships>";
                                amlStr += "<Item type='TOC Access' action='delete' id='" + tocId + "'>";
                                amlStr += "</Item>";
                                amlStr += "</Relationships></Item>";
                            }
                        }
                    }
                }

                if (model.AuthList != null && model.AuthList.Count > 0)
                {
                    for (int i = 0; i < model.AuthList.Count; i++)
                    {
                        string value   = model.AuthList[i];
                        bool   isExist = false;
                        for (int j = 0; j < item.getItemCount(); j++)
                        {
                            var    itemObj   = item.getItemByIndex(j);
                            string keyedName = itemObj.getProperty("keyed_name");
                            if (keyedName.Trim() == value)
                            {
                                isExist = true;
                            }
                        }
                        //如果不存在新增
                        if (!isExist)
                        {
                            result = ItemTypeDA.GetItemTypeByName(inn, value);
                            if (!string.IsNullOrEmpty(result.getErrorString()))
                            {
                                retModel.AddError("errorMessage", result.getErrorString());
                                return(Json(retModel, JsonRequestBehavior.AllowGet));
                            }
                            string typeId = result.getProperty("id");
                            if (!string.IsNullOrEmpty(typeId))
                            {
                                amlStr += "<Item type='ITEMTYPE' action='edit' id='" + typeId + "'><Relationships>";
                                amlStr += "<Item type='TOC Access' action='add'>";
                                amlStr += "<related_id> ";
                                amlStr += "<Item type='IDENTITY' action='get'><name>" + model.KEYED_NAME + "</name></Item>";
                                amlStr += "</related_id></Item>";
                                amlStr += "</Relationships></Item>";
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(amlStr))
                {
                    amlStr = "<AML>" + amlStr + "</AML>";
                    result = inn.applyAML(amlStr);
                    if (!string.IsNullOrEmpty(result.getErrorString()))
                    {
                        retModel.AddError("errorMessage", result.getErrorString());
                    }
                }
                //if(item.getItemCount()>0)
                //{
                //    //不存在的新增
                //    for(int index=0;index< item.getItemCount();index++)
                //    {
                //        var itemObj = item.getItemByIndex(index);
                //        string keyedName = item.getProperty("keyed_name");
                //        string value= model.AuthList.Where(x => x == keyedName.Trim()).FirstOrDefault();
                //        if(string.IsNullOrEmpty(value))
                //        {
                //            amlStr += "<Item type='TOC Access' action='add'>";
                //            amlStr += "<related_id> ";
                //            amlStr += "<Item type='IDENTITY' action='get'><name>" + value + "</name></Item>";
                //            amlStr += "</related_id></Item>";
                //        }
                //    }

                //}
                //if (model)
                //List<Item> itemTypes = new List<Item>();
                //if(itemTypes)
            }
            catch (Exception ex)
            {
                retModel.AddError("errorMessage", ex.Message);
            }
            return(Json(retModel, JsonRequestBehavior.AllowGet));
        }
        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);
        }