Esempio n. 1
0
    /// <summary>
    /// 设置用户密码
    /// </summary>
    protected void SetPassword()
    {
        string strUserID = LogInfo.UserInfo.ID;

        if (Request["strUserID"] != null)
        {
            strUserID = Request["strUserID"].ToString();
        }

        if (USER_PWD_ORG.Text == "" && LogInfo.UserInfo.ID != "000000001")
        {
            Alert("请输入原密码");
            lbMsg.Text = "请输入原密码";
            return;
        }
        //修改 潘德军,2013-8-5,修改原逻辑错误
        if (LogInfo.UserInfo.ID != "000000001")
        {
            TSysUserVo objUserVo_Temp = new TSysUserVo();
            objUserVo_Temp.USER_NAME = USER_NAME.Text;
            objUserVo_Temp.USER_PWD  = ToMD5(USER_PWD_ORG.Text);
            TSysUserLogic objUserLogic_Temp = new TSysUserLogic();
            DataTable     dtUserTemp        = objUserLogic_Temp.SelectByTable(objUserVo_Temp);
            if (dtUserTemp.Rows.Count <= 0 && LogInfo.UserInfo.ID != "000000001")
            {
                Alert("请输入正确的原密码");
                lbMsg.Text = "请输入正确的原密码";
                return;
            }
        }
        if (USER_PWD.Text != USER_PWD_CONFIRM.Text)
        {
            Alert("两次输入的新密码不一致,请重新输入");
            lbMsg.Text = "两次输入的新密码不一致,请重新输入";
            return;
        }
        //修改密码
        TSysUserVo objUserVo = new TSysUserVo();
        //objUserVo = (TSysUserVo)BindControlsToObjectMode(objUserVo);
        TSysUserLogic logicUser = new TSysUserLogic(objUserVo);

        objUserVo.USER_PWD = ToMD5(USER_PWD.Text);//密码要加密
        objUserVo.ID       = strUserID;
        if (logicUser.Edit(objUserVo))
        {
            Alert("修改成功");
            lbMsg.Text = "修改成功";
            base.WriteLog(i3.ValueObject.ObjectBase.LogType.EditPassWord, objUserVo.ID, LogInfo.UserInfo.USER_NAME + "修改用户: " + objUserVo.USER_NAME + " 的密码成功!");
        }
        else
        {
            Alert("修改失败");
            lbMsg.Text = "修改失败";
        }
    }
    /// <summary>
    /// 登陆主函数
    /// </summary>
    protected void LogIn()
    {
        //先隐藏
        lblCount.Visible = false;
        //登录
        TSysUserVo userInfo = new TSysUserVo();

        userInfo.USER_NAME = username.Text;
        userInfo.USER_PWD  = ToMD5(password.Text);
        if (string.IsNullOrEmpty(username.Text))
        {
            Alert("请输入帐号");
            return;
        }
        if (string.IsNullOrEmpty(password.Text))
        {
            Alert("请输入密码");
            return;
        }
        TSysUserLogic uil = new TSysUserLogic();
        DataTable     dt  = uil.SelectByTable(userInfo);

        if (dt.TableName != "")
        {
            string[] strMessage = dt.TableName.Replace("\n", "").Split(':');
            if (strMessage.Length == 3)
            {
                Alert("连接异常!\\n" + "异常代码: " + strMessage[0] + "\\n" + "异常原因:" + strMessage[1] + strMessage[2]);
            }
            else if (strMessage.Length == 2)
            {
                Alert("连接异常!\\n" + "异常代码: " + strMessage[0] + "\\n" + "异常原因:" + strMessage[1]);
            }
            else
            {
                Alert("连接异常!\\n" + "异常原因: " + dt.TableName.Replace("\n", ""));
            }
            return;
        }
        if (dt.Rows.Count > 0)
        {//登录成功,返回到指定地址
            if (dt.Rows[0][TSysUserVo.IS_USE_FIELD].ToString() == "0")
            {
                //已经锁定,提示已锁定
                Alert("用户已锁定,请联系管理员处理!");
            }
            else if (dt.Rows[0][TSysUserVo.IS_DEL_FIELD].ToString() == "1")
            {
                //已经删除,提示已删除
                Alert("用户已删除,请联系管理员处理!");
            }
            else
            {
                //寄存变量
                TSysUserVo  userInfoLogin = uil.Details(dt.Rows[0][TSysUserVo.ID_FIELD].ToString());
                UserLogInfo userLog       = new UserLogInfo();
                userLog.UserInfo           = userInfoLogin;
                userLog.ClientInfo         = new LoginClientData();
                Session[KEY_CACHEOPERATOR] = userLog;
                LogInfo.UserInfo           = userInfoLogin;
                //消除登录错误列表中的相关数据
                if (null != Application[KEY_USER_LOGIN_ERROR])
                {
                    List <UserLogError> loginErrorList = (List <UserLogError>)Application[KEY_USER_LOGIN_ERROR];
                    foreach (UserLogError ule in loginErrorList)
                    {
                        if (ule._userName == userInfo.USER_NAME)
                        {
                            loginErrorList.Remove(ule);
                            break;
                        }
                    }
                }
                userLog.ClientInfo.UserHostAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
                base.WriteLog(i3.ValueObject.ObjectBase.LogType.LogIn, userLog.UserInfo.ID, userLog.UserInfo.USER_NAME + "登陆系统成功!");

                WebApplication.CCFlowFacade.UserLogin(userInfo.USER_NAME);
                Response.Redirect("IndexNew.aspx");

                //if (LogInfo.UserInfo.ID == "000000001")//系统管理员初始化配置
                //{
                //    if (GetIintRegionCode() == "" || GetIintUnitID() == "")
                //    {
                //        Response.Redirect("../Sys/SysInit.aspx");
                //    }
                //    else
                //        Response.Redirect("Index.aspx");
                //}
                //else
                //{
                //    Response.Redirect("Index.aspx");
                //}
            }
        }
        else
        {
            //纠错,记录登录错误次数
            List <UserLogError> loginErrorList;
            int iErrorTimes = 0;
            if (null == Application[KEY_USER_LOGIN_ERROR])
            {
                Application[KEY_USER_LOGIN_ERROR] = new List <UserLogError>();
            }

            loginErrorList = (List <UserLogError>)Application[KEY_USER_LOGIN_ERROR];
            bool bIsHave = false;
            bool bIsLock = false;
            foreach (UserLogError ule in loginErrorList)
            {
                if (ule._userName == userInfo.USER_NAME)
                {
                    //哨兵已发现此用户登录错误过
                    bIsHave = true;
                    //看是否时间已过24小时
                    if (((TimeSpan)(DateTime.Now - ule._loginStartTime)).TotalSeconds > (iMaxHour * 60 * 60))
                    {
                        //清空原始登录错误信息
                        loginErrorList.Remove(ule);
                        return;
                    }
                    //假如超过某此,要停掉此用户
                    if (ule._loginTimes >= iMaxErrorTimes)
                    {
                        //超过5次要被记录入数据库,并锁定用户
                        //userInfo.IS_USE = "1";//2014-02-12 取消该限制
                        userInfo.USER_PWD = "";
                        //userInfo.REMARK = DateTime.Now.ToString() + "登录失败次数超过" + iMaxErrorTimes + "次,系统自动锁定";//2014-02-12 取消该限制

                        TSysUserVo objTemp = new TSysUserVo();
                        objTemp.USER_NAME = userInfo.USER_NAME;
                        objTemp           = new TSysUserLogic().Details(objTemp);
                        if (objTemp.ID != "000000001")
                        {
                            new TSysUserLogic().EditByName(userInfo);
                        }
                        //bIsLock = true;//2014-02-12 取消该限制
                        // 每超过1此,重新置零,防止重复刷日志
                        //ule._loginTimes = 0;
                    }
                    //要是提示超前了,下面两句话,对调下就行了
                    ule._loginTimes = ule._loginTimes + 1;
                    iErrorTimes     = ule._loginTimes;
                }
            }
            //哨兵没有发现此用户以前登录错误过,现在记录入
            if (!bIsHave)
            {
                UserLogError ule = new UserLogError();
                ule._loginIP        = "";
                ule._loginStartTime = DateTime.Now;
                ule._loginTimes     = 1;
                ule._loginType      = "登录";
                ule._userName       = userInfo.USER_NAME;
                loginErrorList.Add(ule);
                iErrorTimes = ule._loginTimes;
            }
            //提示出错信息
            if (!bIsLock)
            {
                Alert("用户名或密码错误," + "您已经是有" + iErrorTimes.ToString() + "次登录错误了," + "如果连续错误5次系统将锁定此用户!");
            }
            else
            {
                Alert("您尝试次数过多,此用户已锁定,请联系管理员处理!");
            }
        }
    }