Пример #1
0
        /// <summary>
        /// 按用户名登录(LDAP专用)
        /// </summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="systemCode">子系统编码</param>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public UserLogonResult LogonByUserName(string taskId, string systemCode, BaseUserInfo userInfo, string userName)
        {
            var result = new UserLogonResult();

            var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                // 先侦测是否在线
                //userLogonManager.CheckOnline();
                // 然后获取用户密码
                var userManager = new BaseUserManager(userInfo);
                // 是否从角色判断管理员
                userManager.CheckIsAdministrator = true;
                //根据用户名获取用户信息
                var userEntity = userManager.GetByUserName(userName);


                if (userEntity != null)
                {
                    var baseUserLogonManager = new BaseUserLogonManager(userInfo);
                    //获取密码
                    var userLogonEntity = baseUserLogonManager.GetEntityByUserId(userEntity.Id);
                    var password        = userLogonEntity.UserPassword;
                    //再进行登录,这里密码不能是AD的密码,所以不检验密码
                    result = userManager.LogonByUserName(userName, password, systemCode, null, null, null, false, false);
                    //可以登录,但不建议,没有登录日志等
                    //result = userManager.LogonByOpenId(openId, string.Empty, string.Empty);
                }
                // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                //BaseLogManager.Instance.Add(userInfo, this.serviceName, MethodBase.GetCurrentMethod());
            });
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 锁定用户
        /// </summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <returns>是否成功锁定</returns>
        public bool LockUser(string taskId, BaseUserInfo userInfo, string userName)
        {
            var result = false;

            var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                // BaseLogManager.Instance.Add(result, this.serviceName, AppMessage.LogonService_LockUser, MethodBase.GetCurrentMethod());
                var userManager = new BaseUserManager(userInfo);
                var parameters  = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0)
                };
                var userEntity = BaseEntity.Create <BaseUserEntity>(userManager.GetDataTable(parameters));
                // 判断是否为空的
                if (userEntity != null && userEntity.Id > 0)
                {
                    // 被锁定15分钟,不允许15分钟内登录,这时间是按服务器的时间来的。
                    var userLogonManager          = new BaseUserLogonManager();
                    var userLogonEntity           = userLogonManager.GetEntityByUserId(userEntity.Id);
                    userLogonEntity.LockStartTime = DateTime.Now;
                    userLogonEntity.LockEndTime   = DateTime.Now.AddMinutes(BaseSystemInfo.PasswordErrorLockCycle);
                    result = userLogonManager.UpdateEntity(userLogonEntity) > 0;
                }
            });

            return(result);
        }
        /// <summary>
        /// 检查IP地址
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="ipAddress"></param>
        /// <param name="autoAdd"></param>
        /// <returns></returns>
        public static bool CheckIpAddressByCache(string userId, string ipAddress, bool autoAdd = false)
        {
            // 判断用户是否限制ip访问,有的是不限制访问的
            var userLogonManager = new BaseUserLogonManager();
            var userLogonEntity  = userLogonManager.GetEntityByUserId(userId);

            return(CheckIpAddressByCache(userId, userLogonEntity, ipAddress, autoAdd));
        }
        /// <summary>
        /// 检查用户的登录许可信息
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <returns>用户登录信息</returns>
        public UserLogonResult CheckUser(string userId)
        {
            // 这个从缓存获取,效率高,一般不会有经常在修改的事情,缓存的时间很短才可以,否则读取脏数据了
            var userEntity = GetEntity(userId);

            // 获取登录状态表
            var userLogonManager = new BaseUserLogonManager(UserInfo, UserLogonTable);
            var userLogonEntity  = userLogonManager.GetEntityByUserId(userId);

            return(CheckUser(userEntity, userLogonEntity));
        }
Пример #5
0
        /// <summary>
        /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的
        /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作
        /// </summary>
        /// <param name="userId">主键</param>
        /// <returns>用户信息</returns>
        public static BaseUserLogonEntity SetCache(string userId)
        {
            BaseUserLogonEntity result = null;

            var manager = new BaseUserLogonManager();

            result = manager.GetEntityByUserId(userId);
            if (result != null)
            {
                SetCache(result);
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// 导入用户
        /// </summary>
        /// <param name="dataReader"></param>
        /// <param name="organizationManager"></param>
        /// <param name="userLogonManager"></param>
        /// <param name="userContactManager"></param>
        /// <returns></returns>
        public int ImportUser(IDataReader dataReader, BaseOrganizationManager organizationManager, BaseUserLogonManager userLogonManager, BaseUserContactManager userContactManager)
        {
            var result     = 0;
            var userEntity = GetEntity(dataReader["ID"].ToString());

            if (userEntity == null)
            {
                userEntity = new BaseUserEntity
                {
                    Id = dataReader["ID"].ToString().ToInt()
                };
            }
            userEntity.Id       = dataReader["ID"].ToString().ToInt();
            userEntity.UserFrom = "K8";
            userEntity.UserName = dataReader["USER_NAME"].ToString();
            userEntity.IdCard   = dataReader["ID_Card"].ToString();
            userEntity.Code     = dataReader["EMPLOYEE_CODE"].ToString();
            userEntity.RealName = dataReader["REAL_NAME"].ToString();
            if (string.IsNullOrWhiteSpace(userEntity.RealName))
            {
                userEntity.RealName = dataReader["EMPLOYEE_NAME"].ToString();
            }
            userEntity.NickName    = dataReader["ONLY_USER_NAME"].ToString();
            userEntity.CompanyName = dataReader["OWNER_SITE"].ToString();
            userEntity.Description = dataReader["REMARK"].ToString();
            // 把被删除的数据恢复过来
            userEntity.Deleted = 0;
            if (userEntity.CompanyId > 0)
            {
                if (string.IsNullOrEmpty(organizationManager.GetProperty(new KeyValuePair <string, object>(BaseOrganizationEntity.FieldName, userEntity.CompanyName), BaseOrganizationEntity.FieldId)))
                {
                    Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName);
                    return(0);
                }
            }
            // 不是内部组织机构的才进行调整
            if (userEntity.DepartmentId > 0)
            {
                userEntity.DepartmentName = dataReader["DEPT_NAME"].ToString();
            }
            if (!string.IsNullOrEmpty(dataReader["IM_NAME"].ToString()))
            {
                // userEntity.QQ = dataReader["IM_NAME"].ToString();
            }

            userEntity.Enabled = int.Parse(dataReader["BL_LOCK_FLAG"].ToString());
            Console.WriteLine("ImportK8User:"******":" + userEntity.RealName);
            // 02:可以把读取到的数据能写入到用户中心的。
            result = UpdateEntity(userEntity);
            if (result == 0)
            {
                AddEntity(userEntity);
            }
            // 添加用户密码表
            var userLogonEntity = userLogonManager.GetEntityByUserId(userEntity.Id);

            if (userLogonEntity == null)
            {
                userLogonEntity = new BaseUserLogonEntity
                {
                    UserId = userEntity.Id,
                    // 邦定mac地址
                    CheckIpAddress = 1,
                    UserPassword   = dataReader["USER_PASSWD"].ToString(),
                    Salt           = dataReader["SALT"].ToString()
                };
                // 是否检查机器码 MAC地址
                var checkIpAddress = 1;
                int.TryParse(dataReader["BL_CHECK_COMPUTER"].ToString(), out checkIpAddress);
                userLogonEntity.CheckIpAddress = checkIpAddress;
                if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString()))
                {
                    userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
                }
                userLogonManager.AddEntity(userLogonEntity);
            }
            else
            {
                userLogonEntity.UserId       = userEntity.Id;
                userLogonEntity.UserPassword = dataReader["USER_PASSWD"].ToString();
                userLogonEntity.Salt         = dataReader["SALT"].ToString();
                if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString()))
                {
                    userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
                }
                result = userLogonManager.UpdateEntity(userLogonEntity);
            }
            // 用户的联系方式
            var userContactEntity = userContactManager.GetEntityByUserId(userEntity.Id.ToString());

            if (userContactEntity == null)
            {
                userContactEntity = new BaseUserContactEntity
                {
                    UserId = userEntity.Id,
                    Qq     = dataReader["QQ"].ToString(),
                    Mobile = dataReader["Mobile"].ToString(),
                    Email  = dataReader["Email"].ToString()
                };
                userContactManager.AddEntity(userContactEntity);
            }
            else
            {
                if (!string.IsNullOrEmpty(dataReader["QQ"].ToString()))
                {
                    userContactEntity.Qq = dataReader["QQ"].ToString();
                }
                if (!string.IsNullOrEmpty(dataReader["Mobile"].ToString()))
                {
                    userContactEntity.Mobile = dataReader["Mobile"].ToString();
                }
                if (!string.IsNullOrEmpty(dataReader["Email"].ToString()))
                {
                    userContactEntity.Email = dataReader["Email"].ToString();
                }
                userContactManager.AddOrUpdate(userContactEntity);
            }
            return(result);
        }