Пример #1
0
        protected void cmdOK_ServerClick(object sender, System.EventArgs e)
        {
            SessionHelper sessionHelper = SessionHelper.Current(this.Session);

            _facade = new SecurityFacade(base.DataProvider);
            try
            {
                // 未输入用户名
                if (this.txtUserCode.Text.Trim() == string.Empty)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_User_Code_Empty");
                }
                //用户输入密码错误5次
                if (this.loguser.Value != this.txtUserCode.Text.Trim() && this.loguser.Value != string.Empty)
                {
                    this.logintimes.Value = "0";                                                              //登陆用户与上一次的用户不同且不是第一次登陆,输入密码错误次数清零
                }
                if (this.loguser.Value == this.txtUserCode.Text.Trim() || this.loguser.Value == string.Empty) //登陆用户第一次或者和上次登陆的相同
                {
                    this.loguser.Value = this.txtUserCode.Text.Trim();
                    int logtimes = Convert.ToInt32(this.logintimes.Value);
                    logtimes = logtimes + 1;
                    this.logintimes.Value = logtimes.ToString();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                    DataProvider.BeginTransaction();
                    try
                    {
                        string login = "******" + txtUserCode.Text.Trim().ToUpper() + "'";
                        if (logtimes > 5)
                        {
                            ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.Execute(login);                            //密码错误5次将userstat改为L,锁定账户
                            DataProvider.CommitTransaction();
                            this.logintimes.Value = "0";
                            return;
                        }
                    }
                    catch
                    {
                        DataProvider.RollbackTransaction();
                    }
                    finally
                    {
                        ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    }
                }
                // 未输入密码
                if (this.txtPassword.Text.Trim() == string.Empty)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_Password_Empty");
                }

                BenQGuru.eMES.Domain.BaseSetting.User user = this._facade.LoginCheck(FormatHelper.CleanString(this.txtUserCode.Text.ToUpper()), FormatHelper.CleanString(this.txtPassword.Text.ToUpper()));

                // 用户名不存在
                if (user == null)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_User_Not_Exist");
                }
                //新用户必须更改密码,用户限制,锁定账户
                string  userstat = "select userstat from tbluser where usercode ='" + txtUserCode.Text.Trim().ToUpper() + "'";
                DataSet ds       = ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider) this.DataProvider).PersistBroker.Query(userstat);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0][0].ToString() == "C")                   //用户限制
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_User_Confined");
                        return;
                    }
                    else if (ds.Tables[0].Rows[0][0].ToString() == "L")                    //锁定账户
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_User_Locked");
                        return;
                    }

                    /*
                     *                  else if (ds.Tables[0].Rows[0][0].ToString() == "N")//新用户必须更改密码
                     *                  {
                     *                          ExceptionManager.Raise(this.GetType(), "$Error_User_New");
                     *                          return;
                     *                  }
                     */
                }

                // Added By Hi1/Venus.Feng on 20080627 for Hisense Version : Add OrgID
                // 只将User默认的Org放进Session中去
                BaseModelFacade baseFacade = new BaseModelFacade(this.DataProvider);
                object          org        = baseFacade.GetUserDefaultOrgByUser(user.UserCode);
                if (org == null)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_UserDefaultOrg_NotDefined");
                    return;
                }
                GlobalVariables.CurrentOrganizations.Clear();
                GlobalVariables.CurrentOrganizations.Add((Organization)org);
                // End Added

                sessionHelper.IsBelongToAdminGroup = this._facade.IsBelongToAdminGroup(this.txtUserCode.Text.ToUpper());
                sessionHelper.UserName             = user.UserName;
                sessionHelper.UserCode             = user.UserCode;
                sessionHelper.UserMail             = user.UserEmail;
                sessionHelper.Language             = this.drpLanguage.Value;

                //				//sammer kong 20050408 statisical for account of loggin user
                //				if( sessionHelper.UserCode != null )
                //				{
                //					WebStatisical.Instance()["user"].Add( (sessionHelper.UserCode ) );
                //				}

                this.Response.Redirect(this.MakeRedirectUrl("./Warehouse/FMaterialQuery.aspx"), false);
            }
            catch (Exception ex)
            {
                this.lblMessage.Text = MessageCenter.ParserMessage(ex.Message, this.languageComponent1);
            }
        }
Пример #2
0
        protected void cmdOK_ServerClick(object sender, System.EventArgs e)
        {
            //modified by carey.cheng on 2010-05-19 for muti db support
            MesEnviroment.DatabasePosition = this.dprDatabase.Value;

            //IDomainDataProvider DataProvider = BenQGuru.eMES.Common.DomainDataProvider.DomainDataProviderManager.DomainDataProvider(this.dprDatabase.Value);
            //base.DataProvider = DataProvider;
            //end modified by carey.cheng on 2010-05-19 for muti db support

            SessionHelper sessionHelper = SessionHelper.Current(this.Session);

            _facade = new SecurityFacade(base.DataProvider);
            try
            {
                // 未输入用户名
                if (this.txtUserCode.Text.Trim() == string.Empty)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_User_Code_Empty");
                }
                //用户输入密码错误5次
                if (this.loguser.Value != this.txtUserCode.Text.Trim() && this.loguser.Value != string.Empty)
                {
                    this.logintimes.Value = "0";                                                              //登陆用户与上一次的用户不同且不是第一次登陆,输入密码错误次数清零
                }
                if (this.loguser.Value == this.txtUserCode.Text.Trim() || this.loguser.Value == string.Empty) //登陆用户第一次或者和上次登陆的相同
                {
                    this.loguser.Value = this.txtUserCode.Text.Trim();
                    int logtimes = Convert.ToInt32(this.logintimes.Value);
                    logtimes = logtimes + 1;
                    this.logintimes.Value = logtimes.ToString();
                    ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.OpenConnection();
                    DataProvider.BeginTransaction();
                    try
                    {
                        string login = "******" + txtUserCode.Text.Trim().ToUpper() + "'";
                        if (logtimes > 5)
                        {
                            ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.Execute(login);//密码错误5次将userstat改为L,锁定账户
                            DataProvider.CommitTransaction();
                            this.logintimes.Value = "0";
                            return;
                        }
                    }
                    catch
                    {
                        DataProvider.RollbackTransaction();
                    }
                    finally
                    {
                        ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider)DataProvider).PersistBroker.CloseConnection();
                    }
                }
                // 未输入密码
                if (this.txtPassword.Text.Trim() == string.Empty)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_Password_Empty");
                }
                //验证码
                if (ConfigurationManager.AppSettings["NeedValidationCode"] == "Y")
                {
                    if (Session["ImageCode"] != null)
                    {
                        if (txtValidationCode.Text.Trim() != string.Empty)
                        {
                            if (Session["ImageCode"].ToString() != txtValidationCode.Text.Trim().ToString().ToUpper())
                            {
                                ExceptionManager.Raise(this.GetType(), "$Error_ValidationCode_Wrong");
                            }
                        }
                        else
                        {
                            ExceptionManager.Raise(this.GetType(), "$Error_ValidationCode_Empty");
                        }
                    }
                }

                BenQGuru.eMES.Domain.BaseSetting.User user = this._facade.LoginCheck(FormatHelper.CleanString(this.txtUserCode.Text.ToUpper()), FormatHelper.CleanString(this.txtPassword.Text.ToUpper()));

                // 用户名不存在
                if (user == null)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_User_Not_Exist");
                }
                //新用户必须更改密码,用户限制,锁定账户
                string  userstat = "select userstat from tbluser where usercode ='" + txtUserCode.Text.Trim().ToUpper() + "'";
                DataSet ds       = ((BenQGuru.eMES.Common.DomainDataProvider.SQLDomainDataProvider) this.DataProvider).PersistBroker.Query(userstat);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0][0].ToString() == "C")//用户限制
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_User_Confined");
                        return;
                    }
                    else if (ds.Tables[0].Rows[0][0].ToString() == "L")//锁定账户
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_User_Locked");
                        return;
                    }

                    /*
                     *                  else if (ds.Tables[0].Rows[0][0].ToString() == "N")//新用户必须更改密码
                     *                  {
                     *                          ExceptionManager.Raise(this.GetType(), "$Error_User_New");
                     *                          return;
                     *                  }
                     */
                }

                // Added By Hi1/Venus.Feng on 20080627 for Hisense Version : Add OrgID
                // 只将User默认的Org放进Session中去
                BaseModelFacade baseFacade = new BaseModelFacade(this.DataProvider);
                object          org        = baseFacade.GetUserDefaultOrgByUser(user.UserCode);
                if (org == null)
                {
                    ExceptionManager.Raise(this.GetType(), "$Error_UserDefaultOrg_NotDefined");
                    return;
                }
                GlobalVariables.CurrentOrganizations.Clear();
                GlobalVariables.CurrentOrganizations.Add((Organization)org);
                // End Added

                sessionHelper.IsBelongToAdminGroup = this._facade.IsBelongToAdminGroup(this.txtUserCode.Text.ToUpper().Trim());
                sessionHelper.UserName             = user.UserName;
                sessionHelper.UserCode             = user.UserCode;
                sessionHelper.UserMail             = user.UserEmail;
                //sessionHelper.Language = this.drpLanguage.Value;
                sessionHelper.Language = this.drpLanguageNew.SelectedValue;

                Log.ClearOldLogFiles(ConfigurationManager.AppSettings.Get("LogKeepDays"));

                //this.Response.Redirect(this.MakeRedirectUrl("./FStartPage.aspx"), false);
                if (!this.CheckLicense())
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                languageComponent1.Language = this.drpLanguageNew.SelectedValue.Trim();
                this.InitPageLanguage(this.languageComponent1, false);
                this.lblMessage.Text = MessageCenter.ParserMessage(ex.Message, this.languageComponent1);
            }
        }