Beispiel #1
0
        public ActionResult Login(string ReturnUrl, int Status = 0, int BindAccountType = 0)
        {
            if (Session["ClientManager"] != null)
            {
                return(Redirect("/Home/Index"));
            }
            HttpCookie cook = Request.Cookies["intfactory_system"];

            if (cook != null)
            {
                if (cook["status"] == "1")
                {
                    string operateip = Common.Common.GetRequestIP();
                    int    result;
                    IntFactoryEntity.Users model = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(cook["username"], cook["pwd"], out result, operateip);
                    if (model != null)
                    {
                        Session["ClientManager"] = model;
                        return(Redirect("/Home/Index"));
                    }
                }
                else
                {
                    ViewBag.UserName = cook["username"];
                }
            }
            ViewBag.Status          = Status;
            ViewBag.ReturnUrl       = ReturnUrl ?? string.Empty;
            ViewBag.BindAccountType = BindAccountType;

            return(View());
        }
Beispiel #2
0
 public static string IsLimits(HttpContext httpContext, string menucode)
 {
     if (httpContext.Session["ClientManager"] != null)
     {
         IntFactoryEntity.Users model = (IntFactoryEntity.Users)httpContext.Session["ClientManager"];
         if (model.Menus.Where(m => m.MenuCode == menucode).Count() > 0)
         {
             return("");
         }
     }
     return("nolimits");
 }
Beispiel #3
0
        public JsonResult FinishTask(string taskID, string userID, string clientID)
        {
            int result = 0;

            CurrentUser = OrganizationBusiness.GetUserByUserID(userID, clientID);
            TaskBusiness.FinishTask(taskID, CurrentUser.UserID, Common.Common.GetRequestIP(), CurrentUser.ClientID, out result);
            JsonDictionary.Add("result", result);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Beispiel #4
0
        public JsonResult RegisterClient(string name, string companyName, string loginName, string loginPWD, string code)
        {
            int result = 0;
            Dictionary <string, object> JsonDictionary = new Dictionary <string, object>();

            bool bl = OrganizationBusiness.IsExistLoginName(loginName);

            if (bl)
            {
                result = 2;
            }
            else
            {
                bl = Common.Common.ValidateMobilePhoneCode(loginName, code);
                if (!bl)
                {
                    result = 3;
                }
                else
                {
                    string userid = "";
                    ClientBusiness.InsertClient(EnumRegisterType.Self, EnumAccountType.Mobile, loginName, loginPWD, companyName, name, loginName, "", "", "", "", "", "", string.Empty, out result, out userid);

                    if (result == 1)
                    {
                        string operateip = Common.Common.GetRequestIP();
                        int    outResult;
                        IntFactoryEntity.Users user = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(loginName, loginPWD, out outResult, operateip);
                        if (user != null)
                        {
                            Session["ClientManager"] = user;
                        }

                        Common.Common.ClearMobilePhoneCode(loginName);
                    }
                    else
                    {
                        result = 0;
                    }
                }
            }

            JsonDictionary.Add("Result", result);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Beispiel #5
0
 public static bool IsExistMenu(string menucode)
 {
     if (HttpContext.Current.Session["ClientManager"] != null)
     {
         IntFactoryEntity.Users model = (IntFactoryEntity.Users)HttpContext.Current.Session["ClientManager"];
         if (model.Role.IsDefault == 1)
         {
             return(true);
         }
         if (model.Menus.Where(m => m.MenuCode == menucode).Count() > 0)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
        public JsonResult UpdateTaskEndTime(string taskID, string endTime, string userID, string clientID)
        {
            int      result  = 0;
            DateTime?endDate = null;

            if (!string.IsNullOrEmpty(endTime))
            {
                endDate = DateTime.Parse(endTime);
            }
            CurrentUser = OrganizationBusiness.GetUserByUserID(userID, clientID);

            TaskBusiness.UpdateTaskEndTime(taskID, endDate, CurrentUser.UserID, Common.Common.GetRequestIP(), CurrentUser.ClientID, out result);
            JsonDictionary.Add("result", result);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Beispiel #7
0
        /// <summary>
        /// 修改员工基本信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public JsonResult UpdateUserBaseInfo(string entity, string userID)
        {
            int result = 0;

            if (!string.IsNullOrEmpty(userID))
            {
                bool flag = false;
                JavaScriptSerializer   serializer = new JavaScriptSerializer();
                IntFactoryEntity.Users newItem    = serializer.Deserialize <IntFactoryEntity.Users>(entity);
                IntFactoryEntity.Users item       = OrganizationBusiness.GetUserByUserID(userID, CurrentUser.ClientID);
                flag = OrganizationBusiness.UpdateUserInfo(userID, newItem.Name, item.Jobs, item.Birthday, item.Age.Value, newItem.DepartID,
                                                           newItem.Email, newItem.MobilePhone, item.OfficePhone, CurrentUser.ClientID);
                result = flag ? 1 : 0;
            }
            JsonDictionary.Add("result", result);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        //绑定微信账户
        public int BindWeiXin(Users model)
        {
            int result = 0;
            if (Session["WeiXinTokenInfo"] != null)
            {
                string tokenInfo = Session["WeiXinTokenInfo"].ToString();
                string[] tokenArr = tokenInfo.Split('|');
                if (tokenArr.Length == 3)
                {
                    string access_token = tokenArr[0];
                    string unionid = tokenArr[2];
                    bool flag = ClientBusiness.BindUserWeiXinID(model.ClientID, model.UserID, unionid);
                    if (flag)
                    {
                        model.WeiXinID = unionid;
                        Session["ClientManager"] = model;
                        Session.Remove("WeiXinTokenInfo");
                        result = 1;
                    }
                }
            }
            else{
                result = 5;
            }

            return result;
        }
        //绑定阿里账户
        public int BindAliMember(Users model)
        {
            int result = 0;
            if (Session["AliTokenInfo"] != null)
            {
                var client = ClientBusiness.GetClientDetail(model.ClientID);
                if (string.IsNullOrEmpty(client.AliMemberID))
                {

                    string tokenInfo = Session["AliTokenInfo"].ToString();
                    string[] tokenArr = tokenInfo.Split('|');
                    if (tokenArr.Length == 3)
                    {
                        string access_token = tokenArr[0];
                        string refresh_token = tokenArr[1];
                        string memberId = tokenArr[2];

                        bool flag = AliOrderBusiness.BaseBusiness.AddAliOrderDownloadPlan(model.UserID, memberId, access_token, refresh_token, model.AgentID, model.ClientID);
                        if (flag)
                        {
                            flag = ClientBusiness.BindClientAliMember(model.ClientID, model.UserID, memberId);
                            if (flag)
                            {
                                model.AliToken = access_token;
                                model.AliMemberID = memberId;
                                Session["ClientManager"] = model;
                                Session.Remove("AliTokenInfo");
                                result = 1;
                            }
                        }
                        else
                        {
                            AliOrderBusiness.BaseBusiness.DeleteAliOrderDownloadPlan(model.ClientID);
                        }
                    }
                }
                else{
                    result = 4;
                }
            }
            else {
                result = 5;
            }

            return result;
        }
        public static Users GetUserByUserName(string loginname, string pwd,out int result, string operateip)
        {
            pwd = CloudSalesTool.Encrypt.GetEncryptPwd(pwd, loginname);
            DataSet ds = new OrganizationDAL().GetUserByUserName(loginname, pwd, out result);
            Users model = null;
            if (ds.Tables.Contains("User") && ds.Tables["User"].Rows.Count > 0)
            {
                model = new Users();
                model.FillData(ds.Tables["User"].Rows[0]);

                model.LogGUID = Guid.NewGuid().ToString();

                model.Department = GetDepartmentByID(model.DepartID, model.AgentID);
                model.Role = GetRoleByIDCache(model.RoleID, model.AgentID);
                
                //处理缓存
                if (!Users.ContainsKey(model.AgentID))
                {
                    GetUsers(model.AgentID);
                }
                if (Users[model.AgentID].Where(u => u.UserID == model.UserID).Count() == 0)
                {
                    Users[model.AgentID].Add(model);
                }
                else
                {
                    var user = Users[model.AgentID].Where(u => u.UserID == model.UserID).FirstOrDefault();
                    user.LogGUID = model.LogGUID;
                }

                model.Client = Manage.ClientBusiness.GetClientDetail(model.ClientID);

                //权限
                if (model.Role != null && model.Role.IsDefault == 1)
                {
                    model.Menus = CommonBusiness.ClientMenus;
                }
                else
                {
                    model.Menus = new List<Menu>();
                    foreach (DataRow dr in ds.Tables["Permission"].Rows)
                    {
                        Menu menu = new Menu();
                        menu.FillData(dr);
                        model.Menus.Add(menu);
                    }
                }
            }

            //记录登录日志
            if (model != null)
            {
                LogBusiness.AddLoginLog(loginname, true,Manage.ClientBusiness.GetClientDetail(model.ClientID).AgentID == model.AgentID ? IntFactoryEnum.EnumSystemType.Client : IntFactoryEnum.EnumSystemType.Agent, operateip, model.UserID, model.AgentID, model.ClientID);
            }
            else
            {
                LogBusiness.AddLoginLog(loginname, false, IntFactoryEnum.EnumSystemType.Client, operateip, "", "", "");
            }

            return model;
        }
        public static Users CreateUser(string loginname, string loginpwd, string name, string mobile, string email, string citycode, string address, string jobs,
                               string roleid, string departid, string parentid, string agentid, string clientid, string mduserid, string mdprojectid, int isAppAdmin, string operateid, out int result)
        {
            string userid = Guid.NewGuid().ToString();

            loginpwd = CloudSalesTool.Encrypt.GetEncryptPwd(loginpwd, loginname);

            Users user = null;

            DataTable dt = OrganizationDAL.BaseProvider.CreateUser(userid, loginname, loginpwd, name, mobile, email, citycode, address, jobs, roleid, departid, parentid, agentid, clientid, mduserid, mdprojectid, isAppAdmin, operateid, out result);
            if (dt.Rows.Count > 0)
            {
                user = new Users();
                user.FillData(dt.Rows[0]);

                var cache = GetUsers(user.AgentID).Where(m => m.UserID == user.UserID).FirstOrDefault();
                if (cache == null || string.IsNullOrEmpty(cache.UserID))
                {
                    user.Role = GetRoleByID(user.RoleID, user.AgentID);
                    user.Department = GetDepartmentByID(user.DepartID, user.AgentID);
                    Users[user.AgentID].Add(user);
                }
                else 
                {
                    cache.Status = 1;
                }

                //日志
                LogBusiness.AddActionLog(IntFactoryEnum.EnumSystemType.Client, IntFactoryEnum.EnumLogObjectType.User, EnumLogType.Create, "", operateid, user.AgentID, user.ClientID);
            }
            return user;
        }
        public static List<Users> GetUsers(string agentid)
        {
            if (string.IsNullOrEmpty(agentid))
            {
                return new List<Users>();
            }
            if (!Users.ContainsKey(agentid))
            {
                List<Users> list = new List<IntFactoryEntity.Users>();
                DataTable dt = OrganizationDAL.BaseProvider.GetUsers(agentid);
                foreach (DataRow dr in dt.Rows)
                {
                    Users model = new Users();
                    model.FillData(dr);

                    model.Department = GetDepartmentByID(model.DepartID, agentid);
                    model.Role = GetRoleByIDCache(model.RoleID, agentid);

                    list.Add(model);
                }
                Users.Add(agentid, list);
                return list;
            }
            return Users[agentid].ToList();
        }
        public static List<Users> GetUsers(string keyWords, string departID, string roleID, string agentid, int pageSize, int pageIndex, ref int totalCount, ref int pageCount)
        {
            string whereSql = "AgentID='" + agentid + "' and Status<>9";

            if (!string.IsNullOrEmpty(keyWords))
                whereSql += " and ( Name like '%" + keyWords + "%' or MobilePhone like '%" + keyWords + "%' or Email like '%" + keyWords + "%')";

            if (!string.IsNullOrEmpty(departID))
                whereSql += " and DepartID='" + departID + "'";

            if (!string.IsNullOrEmpty(roleID))
                whereSql += " and RoleID='" + roleID + "'";

            DataTable dt = CommonBusiness.GetPagerData("Users", "*", whereSql, "AutoID", pageSize, pageIndex, out totalCount, out pageCount);
            List<Users> list = new List<Users>();
            Users model;
            foreach (DataRow item in dt.Rows)
            {
                model = new Users();
                model.FillData(item);

                model.CreateUser = GetUserByUserID(model.CreateUserID, model.AgentID);
                model.Department = GetDepartmentByID(model.DepartID, model.AgentID);
                model.Role = GetRoleByIDCache(model.RoleID, model.AgentID);

                list.Add(model);
            }

            return list;
        }
        public static Users GetUserByUserID(string userid, string agentid)
        {
            
            if (string.IsNullOrEmpty(userid) || string.IsNullOrEmpty(agentid))
            {
                return null;
            }
            userid = userid.ToLower();
            var list = GetUsers(agentid);
            if (list.Where(u => u.UserID == userid).Count() > 0)
            {
                return list.Where(u => u.UserID == userid).FirstOrDefault();
            }
            else
            {
                DataTable dt = new OrganizationDAL().GetUserByUserID(userid);
                Users model = new Users();
                if (dt.Rows.Count > 0)
                {
                    model.FillData(dt.Rows[0]);

                    if (agentid == model.AgentID)
                    {
                        model.Department = GetDepartmentByID(model.DepartID, agentid);
                        model.Role = GetRoleByIDCache(model.RoleID, agentid);
                        Users[agentid].Add(model);
                    }
                }
                return model;
            }
        }
Beispiel #15
0
        //登录
        public JsonResult UserLogin(string userName, string pwd, string remember, int bindAccountType)
        {
            int result = 0;
            Dictionary <string, object> resultObj = new Dictionary <string, object>();

            YXERP.Common.PwdErrorUserEntity pwdErrorUser = null;

            if (Common.Common.CachePwdErrorUsers.ContainsKey(userName))
            {
                pwdErrorUser = Common.Common.CachePwdErrorUsers[userName];
            }

            if (pwdErrorUser == null || (pwdErrorUser.ErrorCount < 10 && pwdErrorUser.ForbidTime < DateTime.Now))
            {
                string operateip = Common.Common.GetRequestIP();
                int    outResult;
                IntFactoryEntity.Users model = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(userName, pwd, out outResult, operateip);
                if (model != null)
                {
                    if (model.Status.Value == 1)
                    {
                        //保持登录状态
                        HttpCookie cook = new HttpCookie("intfactory_system");
                        cook["username"] = userName;
                        cook["pwd"]      = pwd;
                        if (remember == "1")
                        {
                            cook["status"] = remember;
                        }
                        cook.Expires = DateTime.Now.AddDays(7);
                        Response.Cookies.Add(cook);

                        //将阿里账户绑定到已有账户
                        if (bindAccountType == 1)
                        {
                            result = BindAliMember(model);
                        }
                        //将微信账户绑定到已有账户
                        else if (bindAccountType == 2)
                        {
                            result = BindWeiXin(model);
                        }
                        else if (bindAccountType == 10000) //授权第三方登录
                        {
                            result = 1;
                            resultObj.Add("userid", model.UserID);
                            resultObj.Add("clientid", model.ClientID);
                            resultObj.Add("sign", Signature.GetSignature(Common.Common.YXAppKey, Common.Common.YXAppSecret, model.UserID));
                        }
                        else
                        {
                            Session["ClientManager"] = model;
                            result = 1;
                        }

                        Common.Common.CachePwdErrorUsers.Remove(userName);
                    }
                    else
                    {
                        if (model.Status.Value == 9)
                        {
                            result = 9;
                        }
                    }
                }
                else
                {
                    //密码错误
                    if (outResult == 3)
                    {
                        if (pwdErrorUser == null)
                        {
                            pwdErrorUser = new Common.PwdErrorUserEntity();
                        }
                        else
                        {
                            if (pwdErrorUser.ErrorCount > 9)
                            {
                                pwdErrorUser.ErrorCount = 0;
                            }
                        }

                        pwdErrorUser.ErrorCount++;
                        if (pwdErrorUser.ErrorCount > 9)
                        {
                            pwdErrorUser.ForbidTime = DateTime.Now.AddHours(2);
                            result = 2;
                        }
                        else
                        {
                            resultObj.Add("errorCount", pwdErrorUser.ErrorCount);
                            result = 3;
                        }

                        Common.Common.CachePwdErrorUsers[userName] = pwdErrorUser;
                    }
                }
            }
            else
            {
                int forbidTime = (int)(pwdErrorUser.ForbidTime - DateTime.Now).TotalMinutes;
                resultObj.Add("forbidTime", forbidTime);
                result = -1;
            }
            resultObj.Add("result", result);

            return(new JsonResult
            {
                Data = resultObj,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }