Exemplo n.º 1
0
        /// <summary>
        /// 增加一个会员信息到在线列表中。用户login.aspx或在线用户信息超时,但用户仍在线的情况下重新生成用户在线列表
        /// </summary>
        /// <param name="uid"></param>
        private static OnlineUserInfo CreateUser(int UserID, int timeout)
        {
            OnlineUserInfo onlineuserinfo = new OnlineUserInfo();

            if (UserID > 0)
            {
                UserInfo ui = BLL.tbUserInfo.GetUserInfoModel(UserID);
                if (ui != null)
                {
                    onlineuserinfo.UserID    = UserID;
                    onlineuserinfo.oUserName = ui.uName.Trim();

                    onlineuserinfo.oIP         = HTTPRequest.GetIP();
                    onlineuserinfo.oAppendTime = DateTime.Parse(Utils.GetDateTime());
                    onlineuserinfo.oLastTime   = DateTime.Parse(Utils.GetDateTime());

                    int olid = Add(onlineuserinfo, timeout);
                    onlineuserinfo.olID = olid;

                    HttpCookie cookie = HttpContext.Current.Request.Cookies["Yannyo"];
                    if (cookie != null)
                    {
                        if (HttpContext.Current.Request.Cookies["Yannyo"]["expires"] != null)
                        {
                            int expires = Utils.StrToInt(HttpContext.Current.Request.Cookies["Yannyo"]["expires"].ToString(), 0);
                            if (expires > 0)
                            {
                                cookie.Expires = DateTime.Now.AddMinutes(Utils.StrToInt(HttpContext.Current.Request.Cookies["Yannyo"]["expires"].ToString(), 0));
                            }
                        }
                    }

                    string cookieDomain = GeneralConfigs.GetConfig().CookieDomain.Trim();
                    if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && UsersUtils.IsValidDomain(HttpContext.Current.Request.Url.Host))
                    {
                        cookie.Domain = cookieDomain;
                    }
                    HttpContext.Current.Response.AppendCookie(cookie);
                }
            }
            else
            {
                onlineuserinfo = CreateGuestUser(timeout);
            }
            return(onlineuserinfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cookie中没有用户ID或则存的的用户ID无效时在在线表中增加一个游客.
        /// </summary>
        public static OnlineUserInfo CreateGuestUser(int timeout)
        {
            OnlineUserInfo onlineuserinfo = new OnlineUserInfo();

            onlineuserinfo.UserID       = -1;
            onlineuserinfo.oUserName    = "******";
            onlineuserinfo.UserGroupsID = 0;
            onlineuserinfo.UserSPID     = 0;
            onlineuserinfo.oIP          = HTTPRequest.GetIP();
            onlineuserinfo.oAppendTime  = DateTime.Parse(Utils.GetDateTime());
            onlineuserinfo.oLastTime    = DateTime.Parse(Utils.GetDateTime());

            int olid = Add(onlineuserinfo, timeout);

            onlineuserinfo.olID = olid;

            return(onlineuserinfo);
        }
Exemplo n.º 3
0
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            getAct       = HTTPRequest.GetString("Act");
            getAdminName = HTTPRequest.GetString("adminName");
            getAdminPwd  = HTTPRequest.GetString("adminPwd");

            comName     = HTTPRequest.GetString("comName");
            comID       = HTTPRequest.GetString("comID");
            comAddress  = HTTPRequest.GetString("comAddress");
            comTel      = HTTPRequest.GetString("comTel");
            orderNum    = HTTPRequest.GetString("orderNum");
            cumNum      = HTTPRequest.GetString("cumNum");
            ordNum      = HTTPRequest.GetString("ordNum");
            pzLen       = HTTPRequest.GetInt("pzLen", 0);
            MonNum      = HTTPRequest.GetInt("MonNum", 0);
            CounNum     = HTTPRequest.GetInt("CounNum", 0);
            oListWidth  = HTTPRequest.GetString("oListWidth");
            pzWidth     = HTTPRequest.GetString("pzWidth");
            pzRow       = HTTPRequest.GetInt("pzRow", 0);
            sOListWidth = HTTPRequest.GetString("sOListWidth");
            sOrderRow   = HTTPRequest.GetInt("sOrderRow", 0);

            if (!ispost)
            {
                if (getAct.IndexOf("install_four") > -1)
                {
                    //设置基本配置
                    ManageConfig                           = GeneralConfigs.GetConfig();
                    ManageConfig.CompanyName               = comName;
                    ManageConfig.RegistrationNo            = comID;
                    ManageConfig.Address                   = comAddress;
                    ManageConfig.Phone                     = comTel;
                    ManageConfig.OrderID                   = orderNum;
                    ManageConfig.SupplierCode              = cumNum;
                    ManageConfig.MonthlyStatementCode      = ordNum;
                    ManageConfig.CertificateCodeLen        = pzLen;
                    ManageConfig.MoneyDecimal              = MonNum;
                    ManageConfig.QuantityDecimal           = CounNum;
                    ManageConfig.PrintPageWidth            = oListWidth;
                    ManageConfig.PrintCertificatePageWidth = pzWidth;
                    ManageConfig.CertificateRow            = pzRow;
                    ManageConfig.PrintAddPageWidth         = sOListWidth;
                    ManageConfig.PrintAddRow               = sOrderRow;

                    GeneralConfigs.Serialiaze(ManageConfig, Yannyo.Common.Utils.GetMapPath(BaseConfigs.GetSysPath + "/config/general.config"));
                    Logs.AddEventLog(this.userid, "修改系统配置.");
                    BaseConfigs.ResetConfig();
                    Caches.ReSet();
                    try
                    {
                        Yannyo.Install.Utils.toSystemReg(ManageConfig);
                    }
                    catch
                    {
                    }

                    if (getAdminName != "" && getAdminPwd != "")
                    {
                        if (!tbUserInfo.ExistsUserInfo(getAdminName))
                        {
                            //创建新用户
                            UserInfo ui = new UserInfo();
                            ui.uName = getAdminName;
                            ui.uPWD  = Yannyo.Common.Utils.MD5(getAdminPwd);
                            ui.uCode = Yannyo.Common.Utils.CutString(Yannyo.Common.Utils.GetRanDomCode(), 16);

                            ui.uLastIP       = HTTPRequest.GetIP();
                            ui.uAppendTime   = DateTime.Now;
                            ui.uUpAppendTime = DateTime.Now;
                            ui.uEstate       = 0;
                            ui.StaffID       = 0;
                            ui.uType         = 0;
                            ui.uPermissions  = "X";
                            if (tbUserInfo.AddUserInfo(ui) > 0)
                            {
                                Logs.AddEventLog(this.userid, "新增用户:" + ui.uName);
                            }
                        }
                        else
                        {
                            this.AddErrLine("系统已经初始化,请不要刷新页面或重新初始化!");
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 用户在线信息维护。判断当前用户的身份(会员还是游客),是否在在线列表中存在,如果存在则更新会员的当前动,不存在则建立.
        /// </summary>
        /// <param name="passwordkey">系统passwordkey</param>
        /// <param name="timeout">在线超时时间</param>
        /// <param name="passwd">用户密码</param>
        public static OnlineUserInfo UpdateInfo(string passwordkey, int timeout, int uid, string passwd)
        {
            lock (SynObject)
            {
                OnlineUserInfo onlineuser = new OnlineUserInfo();

                string ip       = HTTPRequest.GetIP();
                int    userid   = Utils.StrToInt(UsersUtils.GetCookie("UserID"), uid);
                string password = (passwd == string.Empty ? UsersUtils.GetCookiePassword(passwordkey) : UsersUtils.GetCookiePassword(passwd, passwordkey));

                if (password.Length == 0)
                {
                    userid = -1;
                }
                // 如果密码非Base64编码字符串则怀疑被非法篡改, 直接置身份为游客
                else if (!Utils.IsBase64String(password))
                {
                    userid = -1;
                }

                if (userid != -1)
                {
                    onlineuser = GetOnlineUserInfo(userid);

                    if (onlineuser != null)
                    {
                        if (onlineuser.oIP != ip)
                        {
                            UpdateIP(onlineuser.olID, ip);

                            onlineuser.oIP = ip;

                            return(onlineuser);
                        }
                    }
                    else
                    {
                        // 判断密码是否正确
                        userid = BLL.tbUserInfo.CheckPassword(userid, password, false);
                        if (userid != -1)
                        {
                            DeleteRowsByIP(ip);
                            return(CreateUser(userid, timeout));
                        }
                        else
                        {
                            // 如密码错误则在在线表中创建游客
                            onlineuser = GetOnlineUserByIP(-1, ip);
                            if (onlineuser == null)
                            {
                                return(CreateGuestUser(timeout));
                            }
                        }
                    }
                }
                else
                {
                    onlineuser = GetOnlineUserByIP(-1, ip);

                    if (onlineuser == null)
                    {
                        return(CreateGuestUser(timeout));
                    }
                }

                //UpdateLastTime(onlineuser.Olid);

                onlineuser.oLastTime = DateTime.Now;    // DateTime.Parse(Utils.GetDateTime());
                return(onlineuser);
            }
        }
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            if (this.userid > 0)
            {
                if (CheckUserPopedoms("X"))
                {
                    UserTypeList = Caches.GetUserTypeList();
                    Act          = HTTPRequest.GetString("Act");

                    uName        = Utils.ChkSQL(HTTPRequest.GetString("uName"));
                    uPWD         = Utils.ChkSQL(HTTPRequest.GetString("uPWD"));
                    uPWD_Old     = Utils.ChkSQL(HTTPRequest.GetString("uPWD_Old"));
                    uPermissions = Utils.ChkSQL(HTTPRequest.GetString("uPermissions"));
                    uEstate      = Utils.ChkSQL(HTTPRequest.GetString("uEstate"));

                    Erp_Name = Utils.ChkSQL(HTTPRequest.GetString("Erp_Name"));
                    Erp_Pwd  = Utils.ChkSQL(HTTPRequest.GetString("Erp_Pwd"));
                    g_Name   = Utils.ChkSQL(HTTPRequest.GetString("g_Name"));
                    g_PWD    = Utils.ChkSQL(HTTPRequest.GetString("g_PWD"));
                    uType    = HTTPRequest.GetInt("uType", 0);
                    StaffID  = HTTPRequest.GetInt("StaffID", 0);

                    StorageIDStr = Utils.ChkSQL(HTTPRequest.GetString("StorageIDStr"));

                    StorageIDStr = StorageIDStr.IndexOf("x") > -1 ? "x" : "," + StorageIDStr + ",";

                    pi.Erp_Name = "";
                    pi.Erp_Pwd  = "";
                    pi.g_Name   = "";
                    pi.g_PWD    = "";



                    if (Act == "Edit")
                    {
                        UserID = Utils.StrToInt(HTTPRequest.GetString("uid"), 0);

                        ui = tbUserInfo.GetUserInfoModel(UserID);
                        pi = tbUserInfo.GetUserPassportInfoModel(UserID);
                        if (pi == null)
                        {
                            pi          = new UserPassportInfo();
                            pi.Erp_Name = "";
                            pi.Erp_Pwd  = "";
                            pi.g_Name   = "";
                            pi.g_PWD    = "";
                        }

                        UserPopedomJson = UsersUtils.GetUserPopedomToJsonStr();// UsersUtils.GetUserPopedomToJsonStr(ui.uPermissions);
                    }

                    if (ispost)
                    {
                        if (ui.uPermissions != "X")
                        {
                            ui.uPermissions = uPermissions;
                        }
                        ui.uEstate      = uEstate == "0" ? 0 : 1;
                        ui.uType        = uType;
                        ui.StaffID      = StaffID;
                        ui.StorageIDStr = StorageIDStr;

                        if (Act == "Add")
                        {
                            if (!tbUserInfo.ExistsUserInfo(uName))
                            {
                                ui.uName = uName;
                                ui.uPWD  = Utils.MD5(uPWD);
                                ui.uCode = Utils.CutString(Utils.GetRanDomCode(), 16);

                                ui.uLastIP       = HTTPRequest.GetIP();
                                ui.uAppendTime   = DateTime.Now;
                                ui.uUpAppendTime = DateTime.Now;



                                pi.UserID = tbUserInfo.AddUserInfo(ui);
                                Logs.AddEventLog(this.userid, "新增用户:" + ui.uName);
                                if (pi.UserID > 0)
                                {
                                    pi.Erp_Name = Erp_Name;
                                    pi.Erp_Pwd  = Erp_Pwd;
                                    pi.g_Name   = g_Name;
                                    pi.g_PWD    = g_PWD;

                                    if (tbUserInfo.AddUserPassportInfo(pi) > 0)
                                    {
                                        AddMsgLine("创建成功!");
                                        AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                                    }
                                    else
                                    {
                                        AddErrLine("账户创建成功,但通行证绑定失败!");
                                        AddScript("history.back(1);");
                                    }
                                }
                                else
                                {
                                    AddErrLine("创建失败!");
                                    AddScript("history.back(1);");
                                }
                            }
                            else
                            {
                                AddErrLine("用户名:" + uName + ",已存在,请更换!");
                                AddScript("history.back(1);");
                            }
                        }
                        if (Act == "Edit")
                        {
                            if (UserID > 0)
                            {
                                ui.UserID = UserID;
                                if (uPWD.Trim() != "")
                                {
                                    ui.uPWD = Utils.MD5(uPWD);
                                }
                                else
                                {
                                    ui.uPWD = uPWD_Old;
                                }

                                //超级管理员无需修改权限与状态
                                if (ui.uPermissions == "X")
                                {
                                    ui.uPermissions = "X";
                                    ui.uEstate      = 0;
                                }
                                try
                                {
                                    pi.UserID   = UserID;
                                    pi.Erp_Name = Erp_Name;
                                    pi.Erp_Pwd  = Erp_Pwd;
                                    pi.g_Name   = g_Name;
                                    pi.g_PWD    = g_PWD;

                                    if (tbUserInfo.UserPassportInfoExists(UserID))
                                    {
                                        tbUserInfo.UpdateUserPassportInfo(pi);
                                    }
                                    else
                                    {
                                        tbUserInfo.AddUserPassportInfo(pi);
                                    }

                                    tbUserInfo.UpdateUserInfo(ui);
                                    Logs.AddEventLog(this.userid, "修改用户:" + ui.uName);
                                    AddMsgLine("修改成功!");
                                    AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                                }
                                catch (Exception ex)
                                {
                                    AddErrLine("修改失败!<br/>" + ex);
                                    AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                                }
                            }
                            else
                            {
                                AddErrLine("参数错误,修改失败!");
                                AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                            }
                        }
                    }
                    else
                    {
                        StorageList = tbStorageInfo.GetStorageInfoList(" sState = 0").Tables [0];

                        if (Act == "Add")
                        {
                            ui.UserID       = 0;
                            ui.uName        = "";
                            ui.uPWD         = "";
                            ui.uCode        = "";
                            ui.uEstate      = 0;
                            ui.uPermissions = "";
                            ui.StorageIDStr = "x";
                            UserPopedomJson = UsersUtils.GetUserPopedomToJsonStr();
                        }

                        if (Act == "Del")
                        {
                            try
                            {
                                tbUserInfo.DeleteUserInfo(HTTPRequest.GetString("uid"));
                                Logs.AddEventLog(this.userid, "删除用户:uid=>" + HTTPRequest.GetString("uid"));
                                AddMsgLine("删除成功!");
                                AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                            }
                            catch (Exception ex)
                            {
                                AddErrLine("删除失败!<br/>" + ex);
                                AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                            }
                        }
                    }
                }
                else
                {
                    AddErrLine("权限不足!");
                    AddScript("window.parent.HidBox();");
                }
            }
            else
            {
                AddErrLine("请先登录!");
                SetBackLink("login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer()));
                SetMetaRefresh(1, "login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer()));
            }
        }