Exemplo n.º 1
0
        /// <summary>
        /// 更新修改记录
        /// </summary>
        /// <param name="oldShow"> </param>
        /// <param name="newShow"> </param>

        public void UpdateModifyRecord(ZtoUserEntity oldShow, ZtoUserEntity newShow, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                tableName = this.CurrentTableName + "_LOG";
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(DbHelper, this.UserInfo, tableName);

            foreach (var property in typeof(ZtoUserEntity).GetProperties())
            {
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                var oldValue         = Convert.ToString(property.GetValue(oldShow, null));
                var newValue         = Convert.ToString(property.GetValue(newShow, null));

                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.TableCode         = ZtoUserEntity.TableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(ZtoUserEntity), "TableName");
                record.RecordKey         = oldShow.Id.ToString();
                record.IPAddress         = DotNet.Business.Utilities.GetIPAddress(true);
                record.CreateBy          = UserInfo.RealName;
                record.CreateOn          = DateTime.Now;
                manager.Add(record, true, false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存实体修改记录
        /// </summary>
        /// <param name="newEntity">修改前的实体对象</param>
        /// <param name="oldEntity">修改后的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void UpdateEntityLog(BaseUserLogOnEntity newEntity, BaseUserLogOnEntity oldEntity, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                tableName = BaseUserEntity.TableName + "_LOG";
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(this.UserInfo, tableName);

            foreach (var property in typeof(BaseUserLogOnEntity).GetProperties())
            {
                var oldValue         = Convert.ToString(property.GetValue(oldEntity, null));
                var newValue         = Convert.ToString(property.GetValue(newEntity, null));
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                //不记录创建人、修改人、没有修改的记录
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.TableCode         = this.CurrentTableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(BaseUserLogOnEntity), "TableName");
                record.RecordKey         = oldEntity.Id.ToString();
                record.IPAddress         = Utilities.GetIPAddress(true);
                manager.Add(record, true, false);
            }
        }
Exemplo n.º 3
0
        public void UpdateModifyRecord(HRCheckInEntity oldShow, HRCheckInEntity newShow, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                tableName = this.CurrentTableName + "_LOG";
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(DbHelper, this.UserInfo, tableName);

            foreach (var property in typeof(HRCheckInEntity).GetProperties())
            {
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                var oldValue         = Convert.ToString(property.GetValue(oldShow, null));
                var newValue         = Convert.ToString(property.GetValue(newShow, null));

                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.TableCode         = HRCheckInEntity.TableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(HRCheckInEntity), "TableName");
                record.RecordKey         = oldShow.Id.ToString();
                record.IPAddress         = Utilities.GetIPAddress(true);
                record.CreateBy          = UserInfo.RealName;
                record.CreateOn          = DateTime.Now;
                BaseSequenceManager sequenceManager = new BaseSequenceManager(UserInfo);
                // 序列产生的ID  添加到TAB_EMPLOYEE表
                record.Id = int.Parse(sequenceManager.GetOracleSequence("ZTOA"));
                manager.Add(record, false, false);
            }
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseModifyRecordEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            sqlBuilder.SetWhere(this.PrimaryKey, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseModifyRecordEntity entity)
        {
            string     key        = string.Empty;
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, this.PrimaryKey);
            if (!this.Identity)
            {
                // 这里已经是指定了主键了,所以不需要返回主键了
                sqlBuilder.ReturnId = false;
                sqlBuilder.SetValue(this.PrimaryKey, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(this.PrimaryKey, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(this.PrimaryKey, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        BaseSequenceManager sequenceManager = new BaseSequenceManager();
                        entity.Id = int.Parse(sequenceManager.Increment(this.CurrentTableName));
                        sqlBuilder.SetValue(this.PrimaryKey, entity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseModifyRecordEntity.FieldCreateOn);
            if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                key = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
            {
                return(entity.Id.ToString());
            }
            return(key);
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseModifyRecordEntity entity)
 {
     SetObjectExpand(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableCode, entity.TableCode);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableDescription, entity.TableDescription);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnCode, entity.ColumnCode);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnDescription, entity.ColumnDescription);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldRecordKey, entity.RecordKey);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldKey, entity.OldKey);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldValue, entity.OldValue);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewKey, entity.NewKey);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewValue, entity.NewValue);
     sqlBuilder.SetValue(BaseModifyRecordEntity.FieldIPAddress, entity.IPAddress);
 }
        /// <summary>
        /// 添加, 这里可以人工干预,提高程序的性能
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
        /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
        /// <returns>主键</returns>
        public string Add(BaseModifyRecordEntity entity, bool identity = true, bool returnId = true)
        {
            string result = string.Empty;

            this.Identity = identity;
            this.ReturnId = returnId;
            result        = this.AddObject(entity);

            if (!string.IsNullOrEmpty(result))
            {
                entity.Id = int.Parse(result);
            }

            return(entity.Id.ToString());
        }
 // 这个是声明扩展方法
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseModifyRecordEntity entity);
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(BaseModifyRecordEntity entity)
 {
     return(this.UpdateObject(entity));
 }
Exemplo n.º 10
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="userId">用户主键、方便外部系统调用,若能传递参数过来</param>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>影响行数</returns>
        public virtual BaseUserInfo ChangePassword(string userId, string oldPassword, string newPassword)
        {
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            #endif

            string encryptOldPassword = oldPassword;
            string encryptNewPassword = newPassword;

            BaseUserInfo userInfo = null;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    this.StatusCode = Status.PasswordCanNotBeNull.ToString();
                    return(userInfo);
                }
            }
            // 判断输入原始密码是否正确
            BaseUserLogOnEntity entity = new BaseUserLogOnManager(this.DbHelper, this.UserInfo).GetObject(UserInfo.Id);
            if (entity.UserPassword == null)
            {
                entity.UserPassword = string.Empty;
            }

            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                encryptOldPassword = this.EncryptUserPassword(oldPassword, entity.Salt);
            }

            // 密码错误
            if (!entity.UserPassword.Equals(encryptOldPassword, StringComparison.CurrentCultureIgnoreCase))
            {
                this.StatusCode = Status.OldPasswordError.ToString();
                return(userInfo);
            }
            // 对比是否最近2次用过这个密码
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                /*
                 * int i = 0;
                 * BaseParameterManager manager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                 * var dt = manager.GetDataTableParameterCode("User", this.UserInfo.Id, "Password");
                 * foreach (DataRow dr in dt.Rows)
                 * {
                 *  string parameter = dr[BaseParameterEntity.FieldParameterContent].ToString();
                 *  if (parameter.Equals(newPassword))
                 *  {
                 *      this.StatusCode = Status.PasswordCanNotBeRepeat.ToString();
                 *      return userInfo;
                 *  }
                 *  i++;
                 *  {
                 *      // 判断连续2个密码就是可以了
                 *      if (i > 2)
                 *      {
                 *          break;
                 *      }
                 *  }
                 * }
                 */
            }

            // 更改密码,同时修改密码的修改日期,这里需要兼容多数据库
            string salt = string.Empty;
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                salt = BaseRandom.GetRandomString(20);
                encryptNewPassword = this.EncryptUserPassword(newPassword, salt);
            }
            SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper);
            sqlBuilder.BeginUpdate(BaseUserLogOnEntity.TableName);
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                sqlBuilder.SetValue(BaseUserLogOnEntity.FieldSalt, salt);
            }
            // 宋彪:此处增加更新密码强度级别
            sqlBuilder.SetValue(BaseUserLogOnEntity.FieldPasswordStrength, SecretUtil.GetUserPassWordRate(newPassword));
            sqlBuilder.SetValue(BaseUserLogOnEntity.FieldUserPassword, encryptNewPassword);
            // 2015-08-04 吉日嘎拉 修改了密码后,把需要修改密码字段设置为 0
            sqlBuilder.SetValue(BaseUserLogOnEntity.FieldNeedModifyPassword, 0);
            sqlBuilder.SetDBNow(BaseUserLogOnEntity.FieldChangePasswordDate);
            sqlBuilder.SetWhere(BaseUserLogOnEntity.FieldId, userId);
            int result = sqlBuilder.EndUpdate();

            if (result == 1)
            {
                // 2015-12-09 吉日嘎拉 确认已经记录了修改密码日志
                // BaseLoginLogManager.AddLog(this.UserInfo, Status.ChangePassword.ToDescription());

                // 2015-12-09 吉日嘎拉 增加日志功能、谁什么时候设置了谁的密码?
                var record = new BaseModifyRecordEntity();
                record.TableCode         = BaseUserLogOnEntity.TableName.ToUpper();
                record.TableDescription  = "用户登录信息表";
                record.ColumnCode        = BaseUserLogOnEntity.FieldUserPassword;
                record.ColumnDescription = "用户密码";
                record.RecordKey         = userId;
                record.NewValue          = "修改密码";
                // record.OldValue = "";
                if (this.UserInfo != null)
                {
                    record.IPAddress    = this.UserInfo.IPAddress;
                    record.CreateUserId = this.UserInfo.Id;
                    record.CreateOn     = DateTime.Now;
                }
                BaseModifyRecordManager modifyRecordManager = new Business.BaseModifyRecordManager(this.UserInfo, BaseUserEntity.TableName + "_Log");
                modifyRecordManager.Add(record, true, false);

                /*
                 * // 若是强类型密码检查,那就保存密码修改历史,防止最近2-3次的密码相同的功能实现。
                 * if (BaseSystemInfo.CheckPasswordStrength)
                 * {
                 *  BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                 *  BaseParameterEntity parameterEntity = new BaseParameterEntity();
                 *  parameterEntity.CategoryCode = "User";
                 *  parameterEntity.ParameterId = this.UserInfo.Id;
                 *  parameterEntity.ParameterCode = "Password";
                 *  parameterEntity.ParameterContent = newPassword;
                 *  parameterEntity.DeletionStateCode = 0;
                 *  parameterEntity.Enabled = true;
                 *  parameterEntity.Worked = true;
                 *  parameterManager.AddObject(parameterEntity);
                 * }
                 */

                userInfo = this.LogOnByOpenId(this.UserInfo.OpenId, this.UserInfo.SystemCode).UserInfo;
                // 同步处理其他系统的密码修改动作
                if (BaseSystemInfo.ServerEncryptPassword)
                {
                    // AfterChangePassword(this.UserInfo.Id, salt, oldPassword, newPassword);
                }
                // 修改密码成功,写入状态
                this.StatusCode = Status.ChangePasswordOK.ToString();
            }
            else
            {
                // 数据可能被删除
                this.StatusCode = Status.ErrorDeleted.ToString();
            }

            return(userInfo);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 设置密码
        /// </summary>
        /// <param name="userId">被设置的用户主键</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="unlock">解除锁定</param>
        /// <param name="autoAdd">数据缺少自动补充登录信息</param>
        /// <returns>影响行数</returns>
        public virtual int SetPassword(string userId, string newPassword, bool?unlock = null, bool?autoAdd = null, bool modifyRecord = true)
        {
            int result = 0;

            // 密码强度检查

            /*
             * if (BaseSystemInfo.CheckPasswordStrength)
             * {
             *  if (password.Length == 0)
             *  {
             *      this.StatusCode = StatusCode.PasswordCanNotBeNull.ToString();
             *      return result;
             *  }
             * }
             */
            string encryptPassword = newPassword;
            string salt            = string.Empty;

            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                salt            = BaseRandom.GetRandomString(20);
                encryptPassword = this.EncryptUserPassword(newPassword, salt);
            }
            // 设置密码字段
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldUserPassword, encryptPassword));
            // 需要重新登录才可以,防止正在被人黑中,阻止已经在线上的人
            parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldOpenId, Guid.NewGuid().ToString("N")));
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldSalt, salt));
            }
            parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldChangePasswordDate, DateTime.Now));
            if (unlock.HasValue && unlock.Value == true)
            {
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldEnabled, 1));
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldLockStartDate, null));
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldLockEndDate, null));
            }
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(this.DbHelper, this.UserInfo);

            result = userLogOnManager.SetProperty(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldId, userId), parameters);
            if (result == 0 && autoAdd.HasValue && autoAdd.Value == true)
            {
                BaseUserLogOnEntity userLogOnEntity = new BaseUserLogOnEntity();
                userLogOnEntity.Id = userId;
                userLogOnEntity.ChangePasswordDate = DateTime.Now;
                userLogOnEntity.UserPassword       = encryptPassword;
                userLogOnEntity.Salt    = salt;
                userLogOnEntity.Enabled = 1;
                userLogOnManager.AddObject(userLogOnEntity);
                result = 1;
            }

            // 2015-12-09 吉日嘎拉 增加日志功能、谁什么时候设置了谁的密码?
            if (modifyRecord)
            {
                var record = new BaseModifyRecordEntity();
                record.TableCode         = BaseUserLogOnEntity.TableName.ToUpper();
                record.TableDescription  = "用户登录信息表";
                record.ColumnCode        = BaseUserLogOnEntity.FieldUserPassword;
                record.ColumnDescription = "用户密码";
                record.RecordKey         = userId;
                record.NewValue          = "设置密码";
                // record.OldValue = "";
                if (this.UserInfo != null)
                {
                    record.IPAddress    = this.UserInfo.IPAddress;
                    record.CreateUserId = this.UserInfo.Id;
                    record.CreateOn     = DateTime.Now;
                }
                BaseModifyRecordManager modifyRecordManager = new Business.BaseModifyRecordManager(this.UserInfo, BaseUserEntity.TableName + "_Log");
                modifyRecordManager.Add(record, true, false);
            }

            if (result == 1)
            {
                this.StatusCode = Status.SetPasswordOK.ToString();
                // 调用扩展
                if (BaseSystemInfo.OnInternet && BaseSystemInfo.ServerEncryptPassword)
                {
                    // AfterSetPassword(userId, salt, password);
                }
            }
            else
            {
                // 数据可能被删除
                this.StatusCode = Status.ErrorDeleted.ToString();
            }

            return(result);
        }