Example #1
0
        /// <summary>
        /// 锁定用户
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <returns>是否成功锁定</returns>
        public bool LockUser(BaseUserInfo userInfo, string userName)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            bool returnValue = false;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_LockUser, MethodBase.GetCurrentMethod());
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
                    parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldUserName, userName));
                    parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldEnabled, 1));
                    parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                    BaseUserEntity userEntity = new BaseUserEntity(userManager.GetDataTable(parameters));
                    // 判断是否为空的
                    if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
                    {
                        // 被锁定15分钟,不允许15分钟内登录,这时间是按服务器的时间来的。
                        userEntity.LockStartDate = DateTime.Now;
                        userEntity.LockEndDate = DateTime.Now.AddMinutes(BaseSystemInfo.LockUserPasswordError);
                        returnValue = userManager.UpdateEntity(userEntity) > 0;
                    }
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart, ConsoleColor.Yellow);
            #endif

            return returnValue;
        }