protected void btnSaveSystemUser_Click(object sender, DirectEventArgs e)
        {
            string loginID = this.txtUserLoginID.Text.Trim();

            if (SystemUserWrapper.FindByLoginID(loginID) != null)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = "Error Message : User LoginID is exist!";
                return;
            }


            try
            {
                if (!string.IsNullOrEmpty(this.txtUserEmail.Text.Trim()))
                {
                    Membership.CreateUser(loginID, this.txtUserPassword.Text.Trim(), this.txtUserEmail.Text.Trim());
                }
                else
                {
                    Membership.CreateUser(loginID, this.txtUserPassword.Text.Trim());
                }


                winSystemUserAdd.Hide();
            }
            catch (Exception ex)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = "Error Message : " + ex.Message;
            }
        }
        /// <summary>
        /// 验证用户身份
        /// </summary>
        private void Authentication()
        {
            string string_Token = this.SSOToken;


            if (string.IsNullOrEmpty(string_Token))
            {
                RedirectToLogon(LoginError.TokenWrong);
                return;
            }

            SSOTokenInfo tokenInfo = SSOProvider.GetInfoFromSSFToken(string_Token);

            //判断Token是否在有效期内
            if (!(tokenInfo.LoginDate.AddHours(SSOProvider.SSFTokenValidationPeriod) > DateTime.Now))
            {
                RedirectToLogon(LoginError.TokenExpired);
                return;
            }

            SystemUserWrapper userInfo = SystemUserWrapper.FindByLoginID(tokenInfo.LoginUserID);

            //单点登录判断
            if (tokenInfo.SSOKey != userInfo.SSOKey)
            {
                RedirectToLogon(LoginError.HasLoginInOtherPlace);
                return;
            }

            if (SSOProvider.GetSessionValue(SSOProvider.Session_Key_LoginUser) == null)
            {
                SSOProvider.SetSessionValue(SSOProvider.Session_Key_LoginUser, tokenInfo);
            }
        }
        public override string GetPassword(string username, string answer)
        {
            string password = null;

            if (!EnablePasswordRetrieval)
            {
                throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                     NHibernateProviderSR.
                                                                                     Pwd_RetrievalNotEnabled);
            }
            if (MembershipPasswordFormat.Hashed == PasswordFormat)
            {
                throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                     NHibernateProviderSR.
                                                                                     Pwd_CannotRetrieveHashed);
            }
            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user != null)
            {
                if (RequiresQuestionAndAnswer && !CheckPassword(answer, user.PasswordAnswer, user.PasswordSalt))
                {
                    UpdateFailureCount(username, FailureType.PasswordAnswer);
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               Pwd_IncorrectAnswer));
                }
                if (MembershipPasswordFormat.Encrypted == PasswordFormat)
                {
                    password = UnencodePassword(password);
                }
            }
            return(password);
        }
        public override bool ChangePasswordQuestionAndAnswer(string username, string password,
                                                             string newPasswordQuestion, string newPasswordAnswer)
        {
            bool flag = false;

            if (ValidateUser(username, password))
            {
                SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);
                if (user == null)
                {
                    return(flag);
                }
                try
                {
                    user.PasswordQuestion = newPasswordQuestion;
                    user.PasswordAnswer   = EncodePassword(newPasswordAnswer, user.PasswordSalt);
                    user.LastActivityDate = DateTime.Now;
                    SystemUserWrapper.Update(user);
                    flag = true;
                }
                catch
                {
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               Pwd_UnableToChangeQandA));
                }
            }
            return(flag);
        }
        public bool ChangePassword(string loginID, string newPassword)
        {
            bool flag = false;

            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(loginID);

            if (user == null)
            {
                return(flag);
            }
            try
            {
                user.UserPassword           = EncodePassword(newPassword, user.PasswordSalt);
                user.LastPasswordChangeDate = DateTime.Now;
                user.LastActivityDate       = DateTime.Now;
                SystemUserWrapper.Update(user);
                flag = true;
            }
            catch
            {
                throw new MembershipPasswordException(
                          NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                           NHibernateProviderSR.
                                                                                           Pwd_OpCancelledDueToAccountLocked));
            }

            return(flag);
        }
        public override MembershipUser CreateUser(string username, string password, string email,
                                                  string passwordQuestion, string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            var e = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(e);
            if (e.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }
            if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }
            if (SystemUserWrapper.FindByLoginID(username) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return(null);
            }

            var user = new SystemUserWrapper
            {
                UserName         = username,
                UserLoginID      = username,
                UserPassword     = EncodePassword(password, machineKey.ValidationKey),
                PasswordFormat   = ((int)PasswordFormat),
                PasswordSalt     = machineKey.ValidationKey,
                UserEmail        = email,
                PasswordQuestion = passwordQuestion,
                PasswordAnswer   = passwordAnswer,
                IsApproved       = isApproved
            };

            user.UserCreateDate = DateTime.Now;
            user.FailedPwdAnsAttemptWndStart = DateTime.Parse("1753-1-1");
            user.LastPasswordChangeDate      = DateTime.Parse("1753-1-1");
            user.LastLoginDate            = DateTime.Parse("1753-1-1");
            user.FailedPwdAttemptWndStart = DateTime.Parse("1753-1-1");
            user.LastActivityDate         = DateTime.Parse("1753-1-1");
            user.LastLockedOutDate        = DateTime.Parse("1753-1-1");
            user.Applications.Add(application);
            try
            {
                SystemUserWrapper.Save(user, SystemUserWrapper.GetDeveUserID());
                status = MembershipCreateStatus.Success;
            }
            catch (Exception exception)
            {
                throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                     NHibernateProviderSR.
                                                                                     User_UnableToCreate,
                                                                                     exception);
            }
            return(GetUser(username, false));
        }
 public override void UpdateUser(MembershipUser user)
 {
     try
     {
         SystemUserWrapper.SaveOrUpdate(SystemUserWrapper.FindByLoginID(user.UserName).FromMembershipUser(user));
     }
     catch (Exception exception)
     {
         throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                              NHibernateProviderSR.
                                                                              User_UnableToUpdate,
                                                                              exception);
     }
 }
        protected void BtnLogin_Click(object sender, DirectEventArgs e)
        {
            string loginID   = this.txtUserName.Text.Trim();
            string password  = this.txtPassWord.Text.Trim();
            string checkCode = this.txtCheckCode.Text.Trim();

            if (checkCode != CheckCode.GetCheckCode())
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = "验证码错误!";
                return;
            }

            SystemUserWrapper userWrapper = SystemUserWrapper.FindByLoginID(loginID);

            if (userWrapper == null)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = GetLocalResourceObject("msgLoginFailedUserPasswordError").ToString();
                SystemLogWrapper.LogUserLoginFailed(loginID, HttpUtil.GetIP(this.Request), GetLocalResourceObject("msgLoginFailedUserPasswordError").ToString(), System.DateTime.Now);
                return;
            }

            if (userWrapper.IsLockedOut)
            {
                if (SystemUserWrapper.CheckUserIfDeveloperAdminOrSystemAdmin(loginID))
                {
                    SystemUserWrapper.UnlockUser(loginID);
                }
                else
                {
                    ResourceManager.AjaxSuccess      = false;
                    ResourceManager.AjaxErrorMessage = GetLocalResourceObject("msgLoginFailedUserLockError").ToString();
                    SystemLogWrapper.LogUserLoginFailed(loginID, HttpUtil.GetIP(this.Request), GetLocalResourceObject("msgLoginFailedUserPasswordError").ToString(), System.DateTime.Now);
                    return;
                }
            }


            if (SystemUserWrapper.FindByLoginID(loginID) == null)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = GetLocalResourceObject("msgLoginFailedUserPasswordError").ToString();
                SystemLogWrapper.LogUserLoginFailed(loginID, HttpUtil.GetIP(this.Request), GetLocalResourceObject("msgLoginFailedUserPasswordError").ToString(), System.DateTime.Now);
                return;
            }

            LoginUser(loginID);
        }
        protected void btnSaveSPSClient_Click(object sender, DirectEventArgs e)
        {
            try
            {
                SPSClientWrapper obj = SPSClientWrapper.FindById(int.Parse(hidId.Text.Trim()));

                SystemUserWrapper clientUser = SystemUserWrapper.FindById(obj.UserID);

                if (clientUser.UserLoginID != this.txtUserID.Text.Trim())
                {
                    if (SystemUserWrapper.FindByLoginID(this.txtUserID.Text.Trim()) != null)
                    {
                        ResourceManager.AjaxSuccess      = false;
                        ResourceManager.AjaxErrorMessage = "错误信息:用户已存在。";
                    }
                }


                clientUser.UserLoginID = this.txtUserID.Text.Trim();

                SPSClientWrapper.Update(obj);

                if (this.chkChangePassword.Checked && !string.IsNullOrEmpty(this.txtUserPasword.Text.Trim()))
                {
                    if (!((NHibernateMembershipProvider)Membership.Provider).ChangePassword(clientUser.UserLoginID, this.txtUserPasword.Text.Trim()))
                    {
                        ResourceManager.AjaxSuccess      = false;
                        ResourceManager.AjaxErrorMessage = "Change Password Failed!";
                        return;
                    }
                }



                winSPClientChangeUserLoginInfo.Hide();
                ResourceManager.AjaxSuccess = true;
            }
            catch (Exception ex)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = "Error Message:" + ex.Message;
                return;
            }
        }
        private void UpdateLastLoginDate(string username)
        {
            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user != null)
            {
                try
                {
                    user.LastLoginDate = DateTime.Now;
                    SystemUserWrapper.SaveOrUpdate(user);
                }
                catch (Exception exception)
                {
                    throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                         NHibernateProviderSR.
                                                                                         User_UnableToUpdateLastLoginDate,
                                                                                         exception);
                }
            }
        }
        public override bool ValidateUser(string username, string password)
        {
            bool flag = false;
            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user != null)
            {
                if (CheckPassword(password, user.UserPassword, user.PasswordSalt))
                {
                    if (user.IsApproved)
                    {
                        flag = true;
                        UpdateLastLoginDate(username);
                    }
                    return(flag);
                }
                UpdateFailureCount(username, FailureType.Password);
            }
            return(flag);
        }
        public override bool ChangePassword(string loginID, string oldPassword, string newPassword)
        {
            bool flag = false;

            if (ValidateUser(loginID, oldPassword))
            {
                var e = new ValidatePasswordEventArgs(loginID, newPassword, true);
                OnValidatingPassword(e);
                if (e.Cancel)
                {
                    if (e.FailureInformation != null)
                    {
                        throw e.FailureInformation;
                    }
                    throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                         NHibernateProviderSR.
                                                                                         Pwd_ChangeCancelledDueToNewPassword);
                }
                SystemUserWrapper user = SystemUserWrapper.FindByLoginID(loginID);
                if (user == null)
                {
                    return(flag);
                }
                try
                {
                    user.UserPassword           = EncodePassword(newPassword, user.PasswordSalt);
                    user.LastPasswordChangeDate = DateTime.Now;
                    user.LastActivityDate       = DateTime.Now;
                    SystemUserWrapper.Update(user);
                    flag = true;
                }
                catch
                {
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               Pwd_OpCancelledDueToAccountLocked));
                }
            }
            return(flag);
        }
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }

            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user == null)
            {
                throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                     NHibernateProviderSR.
                                                                                     User_UnableToGet);
            }

            if (userIsOnline)
            {
                UpdateLastActivityDate(user.UserName);
            }

            return(user.ToMembershipUser(Name));
        }
        protected void btnSaveSPSClient_Click(object sender, DirectEventArgs e)
        {
            try
            {
                string loginID = txtUserID.Text.Trim();

                string password = txtUserPasword.Text.Trim();

                if (SystemUserWrapper.FindByLoginID(loginID) != null)
                {
                    ResourceManager.AjaxSuccess      = false;
                    ResourceManager.AjaxErrorMessage = "错误信息:用户已存在。";
                }


                SPSClientWrapper obj = new SPSClientWrapper();
                obj.Name        = this.txtName.Text.Trim();
                obj.Description = this.txtDescription.Text.Trim();
                //obj.RecieveDataUrl = this.txtRecieveDataUrl.Text.Trim();
                //obj.UserID = Convert.ToInt32(this.txtUserID.Text.Trim());
                //obj.SyncData = this.chkSyncData.Checked;
                //obj.OkMessage = this.txtOkMessage.Text.Trim();
                //obj.FailedMessage = this.txtFailedMessage.Text.Trim();
                //obj.SyncType = this.txtSyncType.Text.Trim();
                //obj.Alias = this.txtAlias.Text.Trim();
                obj.InterceptRate         = Convert.ToDecimal(this.txtInterceptRate.Text.Trim());
                obj.DefaultPrice          = Convert.ToDecimal(this.txtDefaultPrice.Text.Trim());
                obj.SycnNotInterceptCount = Convert.ToInt32(this.txtNotInterceptCount.Text.Trim());
                obj.DefaultShowRecordDays = Convert.ToInt32(this.numShowDayRecord.Text.Trim());
                obj.SyncData = chkSyncData.Checked;



                if (obj.SyncData)
                {
                    SPSDataSycnSettingWrapper spsDataSycnSetting = new SPSDataSycnSettingWrapper();

                    spsDataSycnSetting.SycnRetryTimes = Convert.ToInt32(txtSycnRetryTimes.Text);

                    spsDataSycnSetting.SycnMO = fsSyncMO.Collapsed;

                    if (spsDataSycnSetting.SycnMO.HasValue && spsDataSycnSetting.SycnMO.Value)
                    {
                        spsDataSycnSetting.SycnMOUrl           = txtSycnMOUrl.Text.Trim();
                        spsDataSycnSetting.SycnMOOkMessage     = txtSycnMOOkMessage.Text.Trim();
                        spsDataSycnSetting.SycnMOFailedMessage = txtSycnMOFailedMessage.Text.Trim();
                    }
                    else
                    {
                        spsDataSycnSetting.SycnMOUrl           = "";
                        spsDataSycnSetting.SycnMOOkMessage     = "";
                        spsDataSycnSetting.SycnMOFailedMessage = "";
                    }

                    spsDataSycnSetting.SycnMR = fsSyncMR.Collapsed;

                    if (spsDataSycnSetting.SycnMR.HasValue && spsDataSycnSetting.SycnMR.Value)
                    {
                        spsDataSycnSetting.SycnMRUrl           = txtSycnMRUrl.Text.Trim();
                        spsDataSycnSetting.SycnMROkMessage     = txtSycnMROkMessage.Text.Trim();
                        spsDataSycnSetting.SycnMRFailedMessage = txtSycnMRFailedMessage.Text.Trim();
                    }
                    else
                    {
                        spsDataSycnSetting.SycnMRUrl           = "";
                        spsDataSycnSetting.SycnMROkMessage     = "";
                        spsDataSycnSetting.SycnMRFailedMessage = "";
                    }

                    spsDataSycnSetting.SycnSate = fsSyncState.Collapsed;

                    if (spsDataSycnSetting.SycnSate.HasValue && spsDataSycnSetting.SycnSate.Value)
                    {
                        spsDataSycnSetting.SycnSateUrl           = txtSycnStateUrl.Text.Trim();
                        spsDataSycnSetting.SycnSateOkMessage     = txtSycnStateOkMessage.Text.Trim();
                        spsDataSycnSetting.SycnSateFailedMessage = txtSycnStateFailedMessage.Text.Trim();
                    }
                    else
                    {
                        spsDataSycnSetting.SycnSateUrl           = "";
                        spsDataSycnSetting.SycnSateOkMessage     = "";
                        spsDataSycnSetting.SycnSateFailedMessage = "";
                    }

                    SPSDataSycnSettingWrapper.Save(spsDataSycnSetting);

                    obj.SyncDataSetting = spsDataSycnSetting;
                }

                SPSClientWrapper.QuickAdd(obj, loginID, password);

                winSPSClientAdd.Hide();
            }
            catch (Exception ex)
            {
                ResourceManager.AjaxSuccess      = false;
                ResourceManager.AjaxErrorMessage = "错误信息:" + ex.Message;
            }
        }
        private void UpdateFailureCount(string username, FailureType failureType)
        {
            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user != null)
            {
                DateTime now = DateTime.Now;
                int      failedPasswordAttemptCount = 0;
                try
                {
                    switch (failureType)
                    {
                    case FailureType.Password:
                        now = user.FailedPwdAttemptWndStart;
                        failedPasswordAttemptCount = user.FailedPwdAttemptCnt;
                        break;

                    case FailureType.PasswordAnswer:
                        now = user.FailedPwdAnsAttemptWndStart;
                        failedPasswordAttemptCount = user.FailedPwdAnsAttemptCnt;
                        break;
                    }
                    DateTime time2 = now.AddMinutes(PasswordAttemptWindow);
                    if ((failedPasswordAttemptCount == 0) || (DateTime.Now > time2))
                    {
                        switch (failureType)
                        {
                        case FailureType.Password:
                            user.FailedPwdAttemptWndStart = DateTime.Now;
                            user.FailedPwdAttemptCnt      = 1;
                            goto Label_00E7;

                        case FailureType.PasswordAnswer:
                            user.FailedPwdAnsAttemptWndStart = DateTime.Now;
                            user.FailedPwdAnsAttemptCnt      = 1;
                            goto Label_00E7;
                        }
                    }
                    else
                    {
                        failedPasswordAttemptCount++;
                        if (failedPasswordAttemptCount >= MaxInvalidPasswordAttempts)
                        {
                            user.IsLockedOut       = true;
                            user.LastLockedOutDate = DateTime.Now;
                        }
                        else
                        {
                            switch (failureType)
                            {
                            case FailureType.Password:
                                user.FailedPwdAttemptCnt = failedPasswordAttemptCount;
                                goto Label_00E7;

                            case FailureType.PasswordAnswer:
                                user.FailedPwdAnsAttemptCnt = failedPasswordAttemptCount;
                                goto Label_00E7;
                            }
                        }
                    }
Label_00E7:
                    SystemUserWrapper.SaveOrUpdate(user);
                }
                catch (Exception exception)
                {
                    throw NhibernateMembershipProviderExceptionUtil.NewProviderException(this,
                                                                                         NHibernateProviderSR.
                                                                                         User_UnableToUpdateFailureCount,
                                                                                         exception);
                }
            }
        }
        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new MembershipPasswordException(
                          NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                           NHibernateProviderSR.
                                                                                           Pwd_ResetNotEnabled));
            }
            if ((answer == null) && RequiresQuestionAndAnswer)
            {
                UpdateFailureCount(username, FailureType.PasswordAnswer);
                throw new MembershipPasswordException(
                          NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                           NHibernateProviderSR.
                                                                                           Pwd_AnswerRequiredForReset));
            }
            string password = Membership.GeneratePassword(minRequiredPasswordLength,
                                                          MinRequiredNonAlphanumericCharacters);
            var e = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(e);
            if (e.Cancel)
            {
                if (e.FailureInformation != null)
                {
                    throw e.FailureInformation;
                }
                throw new MembershipPasswordException(
                          NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                           NHibernateProviderSR.
                                                                                           Pwd_ResetCancelledDueToNewPassword));
            }
            SystemUserWrapper user = SystemUserWrapper.FindByLoginID(username);

            if (user != null)
            {
                if (user.IsLockedOut)
                {
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               User_IsLockedOut));
                }
                if (RequiresQuestionAndAnswer && !CheckPassword(answer, user.PasswordAnswer, user.PasswordSalt))
                {
                    UpdateFailureCount(username, FailureType.PasswordAnswer);
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               Pwd_IncorrectAnswer));
                }
                try
                {
                    user.UserPassword           = EncodePassword(password, user.PasswordSalt);
                    user.LastPasswordChangeDate = DateTime.Now;
                    user.LastActivityDate       = DateTime.Now;
                    SystemUserWrapper.SaveOrUpdate(user);
                }
                catch
                {
                    throw new MembershipPasswordException(
                              NhibernateMembershipProviderExceptionUtil.FormatExceptionMessage(this,
                                                                                               NHibernateProviderSR.
                                                                                               Pwd_OpCancelledDueToAccountLocked));
                }
            }
            return(password);
        }