Esempio 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;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取Tr代办列表
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static List <TripReimbursementModel> GetTrTodoList(UserInfo user)
        {
            int total = 0;
            //获取委托权限数据
            List <TripReimbursementModel> returnList = new List <TripReimbursementModel>();
            List <string> agentRoles           = AgentSetBll.GetAgentRoles(user, "TripReimbursement");
            List <TripReimbursementModel> list = TripReimbursementController.GetTripReimbursementList(user, out total, null, "", null, null, "", agentRoles);

            foreach (var item in list)
            {
                var result = ActivityDA.GetActivityAuditByLoginInfo(user.inn, item.id, "innovator.B_TRIPREIMBURSEMENTFORM", user.Roles, agentRoles);
                if (!result.isError() && result.getItemCount() > 0)
                {
                    returnList.Add(item);
                }
            }
            return(returnList);
        }
Esempio 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 }));
        }
Esempio 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);
        }