/// <summary>
        /// 按员工的修改信息,把用户信息进行修改
        /// </summary>
        /// <param name="staffId">员工主键</param>
        /// <returns>影响行数</returns>
        public int UpdateUser(string staffId)
        {
            DataTable     dataTable   = this.GetDT(PiStaffTable.FieldId, staffId);
            PiStaffEntity staffEntity = BaseEntity.Create <PiStaffEntity>(dataTable); //new PiStaffEntity(dataTable);

            if (!string.IsNullOrEmpty(staffEntity.UserId))
            {
                // 员工信息改变时,用户信息也跟着改变。
                PiUserManager userManager = new PiUserManager(DBProvider, UserInfo);
                PiUserEntity  userEntity  = userManager.GetEntity(staffEntity.UserId.ToString());
                // userEntity.Company = staffEntity.CompanyName;
                // userEntity.Department = staffEntity.DepartmentName;
                // userEntity.Workgroup = staffEntity.WorkgroupName;

                userEntity.UserName = staffEntity.UserName;
                userEntity.RealName = staffEntity.RealName;
                userEntity.Code     = staffEntity.Code;

                userEntity.Email   = staffEntity.Email;
                userEntity.Enabled = int.Parse(staffEntity.Enabled.ToString());
                // userEntity.Duty = staffEntity.DutyName;
                // userEntity.Title = staffEntity.TitleName;
                userEntity.Gender   = staffEntity.Gender;
                userEntity.Birthday = BusinessLogic.ConvertToNullableDateTime(staffEntity.Birthday);
                userEntity.Mobile   = staffEntity.Mobile;
            }
            return(0);
        }
Example #2
0
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <returns>影响行数</returns>
        public int Update(PiUserEntity userEntity, out string statusCode)
        {
            int returnValue = 0;

            // 检查用户名是否重复
            if (this.Exists(PiUserTable.FieldUserName, userEntity.UserName, PiUserTable.FieldDeleteMark, "0", userEntity.Id))
            {
                // 用户名已重复
                statusCode = StatusCode.ErrorUserExist.ToString();
            }
            else
            {
                if (!string.IsNullOrEmpty(userEntity.Code) && userEntity.Code.Length > 0 && this.Exists(PiUserTable.FieldCode, userEntity.Code, PiUserTable.FieldDeleteMark, "0", userEntity.Id))
                {
                    // 编号已重复
                    statusCode = StatusCode.ErrorCodeExist.ToString();
                }
                else
                {
                    returnValue = this.UpdateEntity(userEntity);
                    statusCode  = returnValue == 0 ? StatusCode.ErrorDeleted.ToString() : StatusCode.OKUpdate.ToString();
                }
            }
            return(returnValue);
        }
Example #3
0
        /// <summary>
        /// 通过单点登录标识登录
        /// </summary>
        /// <param name="openId">单点登录标识</param>
        /// <param name="ipAddress">IP地址</param>
        /// <param name="macAddress">Mac地址</param>
        /// <returns>用户信息</returns>
        public UserInfo LogOnByOpenId(string openId, string ipAddress = null, string macAddress = null)
        {
            UserInfo userInfo = null;

            // 用户没有找到状态
            this.ReturnStatusCode = StatusCode.UserNotFound.ToString();
            // 检查是否有效的合法的参数
            if (!String.IsNullOrEmpty(openId))
            {
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                if (!string.IsNullOrEmpty(openId))
                {
                    parameters.Add(new KeyValuePair <string, object>(PiUserLogOnTable.FieldOpenId, openId));
                }
                // 若是单点登录,那就不能判断ip地址,因为不是直接登录,是间接登录
                if (!string.IsNullOrEmpty(ipAddress))
                {
                    parameters.Add(new KeyValuePair <string, object>(PiUserLogOnTable.FieldIPAddress, ipAddress));
                }
                if (!string.IsNullOrEmpty(macAddress))
                {
                    parameters.Add(new KeyValuePair <string, object>(PiUserLogOnTable.FieldMACAddress, macAddress));
                }

                var dt = new PiUserLogOnManager(this.DBProvider, this.UserInfo).GetDT(parameters);
                if (dt.Rows.Count == 1)
                {
                    PiUserEntity      userEntity      = this.GetEntity(dt.Rows[0][PiUserLogOnTable.FieldId].ToString());
                    PiUserLogOnEntity userLogOnEntity = new PiUserLogOnManager(this.DBProvider, this.UserInfo).GetEntity(userEntity.Id);
                    userInfo = this.LogOn(userEntity.UserName, userLogOnEntity.UserPassword, openId, false, ipAddress, macAddress, false);
                }
            }
            return(userInfo);
        }
        /// <summary>
        /// 根据用户名获取用户实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名称</param>
        /// <returns>用户实体</returns>
        public PiUserEntity GetEntityByUserName(UserInfo userInfo, string userName)
        {
            var          parameter  = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_GetEntity);
            PiUserEntity userEntity = null;

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                userEntity = new PiUserManager(dbProvider, userInfo).GetEntityByUserName(userName);
            });
            return(userEntity);
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <returns>主键</returns>
        public string Add(PiUserEntity userEntity, out string statusCode)
        {
            var returnValue = string.Empty;

            this.BeforeAdd(userEntity, out statusCode);
            if (statusCode == StatusCode.OK.ToString())
            {
                returnValue = this.AddEntity(userEntity);
                this.AfterAdd(userEntity, out statusCode);
            }
            return(returnValue);
        }
Example #6
0
        /// <summary>
        /// 添加短信,可以发给多个人
        /// </summary>
        /// <param name="messageEntity">实体</param>
        /// <param name="receiverIds">接收者ID组</param>
        /// <returns>影响行数</returns>
        public int Send(CiMessageEntity messageEntity, string[] receiverIds, bool saveSend = true)
        {
            PiUserManager userManager = new PiUserManager(DBProvider, UserInfo);
            // 每发一条短信,数据库中需要记录两条记录,他们的CreateUserId都为创建者ID。
            // 接收者多人的话,不要重复设置创建人的记录了,即对发送者来说,只要记录一条记录就够了
            int returnValue = 0;

            messageEntity.CategoryCode = MessageCategory.Receiver.ToString();
            messageEntity.IsNew        = (int)MessageStateCode.New;
            messageEntity.IPAddress    = UserInfo.IPAddress;
            messageEntity.ParentId     = null;
            messageEntity.DeleteMark   = 0;
            messageEntity.Enabled      = 1;
            returnValue++;

            PiUserEntity userEntity = null;

            for (int i = 0; i < receiverIds.Length; i++)
            {
                messageEntity.ParentId     = null;
                messageEntity.Id           = Guid.NewGuid().ToString();
                messageEntity.CategoryCode = MessageCategory.Receiver.ToString();
                messageEntity.ReceiverId   = receiverIds[i];
                userEntity = userManager.GetEntity(receiverIds[i]);
                if (userEntity != null && userEntity.Id != null)
                {
                    messageEntity.ReceiverRealName = userEntity.RealName;
                }
                messageEntity.Enabled = 1;
                messageEntity.IsNew   = 1;
                if (messageEntity.ReceiverId.Equals(UserInfo.Id))
                {
                    messageEntity.IsNew = (int)MessageStateCode.Old;
                }
                // 接收信息
                string parentId = this.Add(messageEntity, false, false);
                if (saveSend)
                {
                    // 已发送信息
                    messageEntity.Id           = Guid.NewGuid().ToString();
                    messageEntity.ParentId     = parentId;
                    messageEntity.CategoryCode = MessageCategory.Send.ToString();
                    messageEntity.DeleteMark   = 0;
                    messageEntity.Enabled      = 0;
                    this.Add(messageEntity, false, false);
                }
                returnValue++;
            }
            return(returnValue);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateEntity(PiUserEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DBProvider);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiUserTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiUserTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiUserTable.FieldModifiedOn);
            sqlBuilder.SetWhere(PiUserTable.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string AddUser(UserInfo userInfo, PiUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            string returnValue   = string.Empty;
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_AddUser);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                returnValue = AddUser(dbProvider, userInfo, userEntity, out returnCode, out returnMessage);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
        public PiUserEntity GetEntityByUserName(string userName)
        {
            PiUserEntity entity     = null;
            var          parameters = new List <KeyValuePair <string, object> > {
                new KeyValuePair <string, object>(PiUserTable.FieldUserName, userName),
                new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1),
                new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
            };
            DataTable dt = this.GetDT(parameters, 0, null);

            if (dt.Rows.Count > 0)
            {
                entity = BaseEntity.Create <PiUserEntity>(dt);
            }
            return(entity);
        }
Example #10
0
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int UpdateUser(UserInfo userInfo, PiUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            int    returnValue   = 0;
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_UpdateUser);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var userManager = new PiUserManager(dbProvider, userInfo);
                returnValue     = userManager.Update(userEntity, out returnCode);
                returnMessage   = userManager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
        /// <summary>
        /// 用户添加之前执行的方法
        /// </summary>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        public void BeforeAdd(PiUserEntity userEntity, out string statusCode)
        {
            statusCode = StatusCode.OK.ToString();

            if (!string.IsNullOrEmpty(userEntity.UserName) && this.Exists(PiUserTable.FieldUserName, userEntity.UserName, PiUserTable.FieldDeleteMark, "0") || DbCommonLibary.Exists(DBProvider, PiStaffTable.TableName, PiStaffTable.FieldUserName, userEntity.UserName, PiStaffTable.FieldDeleteMark, "0"))
            {
                // 用户名已重复
                statusCode = StatusCode.ErrorUserExist.ToString();
            }
            else
            {
                // 检查编号是否重复
                if (!string.IsNullOrEmpty(userEntity.Code) && this.Exists(PiUserTable.FieldCode, userEntity.Code, PiUserTable.FieldDeleteMark, "0"))
                {
                    // 编号已重复
                    statusCode = StatusCode.ErrorCodeExist.ToString();
                }

                if (userEntity.IsStaff == 1)
                {
                    var parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiStaffTable.FieldUserName, userEntity.UserName),
                        new KeyValuePair <string, object>(PiStaffTable.FieldDeleteMark, 0)
                    };
                    if (DbCommonLibary.Exists(DBProvider, PiStaffTable.TableName, parameters))
                    {
                        // 编号已重复
                        statusCode = StatusCode.ErrorNameExist.ToString();
                    }
                    if (!string.IsNullOrEmpty(userEntity.Code))
                    {
                        parameters = new List <KeyValuePair <string, object> >
                        {
                            new KeyValuePair <string, object>(PiStaffTable.FieldCode, userEntity.Code),
                            new KeyValuePair <string, object>(PiStaffTable.FieldDeleteMark, 0)
                        };
                        if (DbCommonLibary.Exists(DBProvider, PiStaffTable.TableName, parameters))
                        {
                            // 编号已重复
                            statusCode = StatusCode.ErrorCodeExist.ToString();
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">SQL语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, PiUserEntity entity)
 {
     sqlBuilder.SetValue(PiUserTable.FieldCode, entity.Code);
     sqlBuilder.SetValue(PiUserTable.FieldUserName, entity.UserName);
     sqlBuilder.SetValue(PiUserTable.FieldRealName, entity.RealName);
     sqlBuilder.SetValue(PiUserTable.FieldRoleId, entity.RoleId);
     sqlBuilder.SetValue(PiUserTable.FieldNickName, entity.NickName);
     sqlBuilder.SetValue(PiUserTable.FieldQuickQuery, entity.QuickQuery);
     sqlBuilder.SetValue(PiUserTable.FieldWorkCategory, entity.WorkCategory);
     sqlBuilder.SetValue(PiUserTable.FieldCompanyId, entity.CompanyId);
     sqlBuilder.SetValue(PiUserTable.FieldCompanyName, entity.CompanyName);
     sqlBuilder.SetValue(PiUserTable.FieldSubCompanyId, entity.SubCompanyId);
     sqlBuilder.SetValue(PiUserTable.FieldSubCompanyName, entity.SubCompanyName);
     sqlBuilder.SetValue(PiUserTable.FieldDepartmentId, entity.DepartmentId);
     sqlBuilder.SetValue(PiUserTable.FieldDepartmentName, entity.DepartmentName);
     sqlBuilder.SetValue(PiUserTable.FieldSubDepartmentId, entity.SubDepartmentId);
     sqlBuilder.SetValue(PiUserTable.FieldSubDepartmentName, entity.SubDepartmentName);
     sqlBuilder.SetValue(PiUserTable.FieldWorkgroupId, entity.WorkgroupId);
     sqlBuilder.SetValue(PiUserTable.FieldWorkgroupName, entity.WorkgroupName);
     sqlBuilder.SetValue(PiUserTable.FieldGender, entity.Gender);
     sqlBuilder.SetValue(PiUserTable.FieldMobile, entity.Mobile);
     sqlBuilder.SetValue(PiUserTable.FieldTelephone, entity.Telephone);
     sqlBuilder.SetValue(PiUserTable.FieldBirthday, entity.Birthday);
     sqlBuilder.SetValue(PiUserTable.FieldDuty, entity.Duty);
     sqlBuilder.SetValue(PiUserTable.FieldTitle, entity.Title);
     sqlBuilder.SetValue(PiUserTable.FieldSecurityLevel, entity.SecurityLevel);
     sqlBuilder.SetValue(PiUserTable.FieldQICQ, entity.QICQ);
     sqlBuilder.SetValue(PiUserTable.FieldEmail, entity.Email);
     sqlBuilder.SetValue(PiUserTable.FieldLang, entity.Lang);
     sqlBuilder.SetValue(PiUserTable.FieldTheme, entity.Theme);
     sqlBuilder.SetValue(PiUserTable.FieldIsStaff, entity.IsStaff);
     sqlBuilder.SetValue(PiUserTable.FieldAuditStatus, entity.AuditStatus);
     sqlBuilder.SetValue(PiUserTable.FieldIsVisible, entity.IsVisible);
     sqlBuilder.SetValue(PiUserTable.FieldSignature, entity.Signature);
     sqlBuilder.SetValue(PiUserTable.FieldUserAddress, entity.UserAddress);
     sqlBuilder.SetValue(PiUserTable.FieldHomeAddress, entity.HomeAddress);
     sqlBuilder.SetValue(PiUserTable.FieldIsDimission, entity.IsDimission);
     sqlBuilder.SetValue(PiUserTable.FieldDimissionDate, entity.DimissionDate);
     sqlBuilder.SetValue(PiUserTable.FieldDimissionCause, entity.DimissionCause);
     sqlBuilder.SetValue(PiUserTable.FieldDimissionWhither, entity.DimissionWhither);
     sqlBuilder.SetValue(PiUserTable.FieldDeleteMark, entity.DeleteMark);
     sqlBuilder.SetValue(PiUserTable.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(PiUserTable.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(PiUserTable.FieldDescription, entity.Description);
 }
Example #13
0
        public bool IsAdministrator(PiUserEntity entity)
        {
            // 用户是超级管理员
            if (entity.Id.Equals("Administrator"))
            {
                return(true);
            }
            if (entity.Code != null && entity.Code.Equals("Administrator"))
            {
                return(true);
            }
            if (entity.UserName != null && entity.UserName.Equals("Administrator"))
            {
                return(true);
            }

            if (this.UserInfo == null)
            {
                return(false);
            }

            // 用户的默认角色是超级管理员
            var roleManager = new PiRoleManager(this.DBProvider, this.UserInfo);
            // 用户默认角色是否为超级管理员
            PiRoleEntity roleEntity = null;

            if (entity.RoleId != null)
            {
                // 用户在超级管理员群里
                string[] roleIds = this.GetRoleIds(entity.Id);
                foreach (string tmpid in roleIds)
                {
                    if (tmpid.Equals(DefaultRole.Administrators.ToString()))
                    {
                        return(true);
                    }
                    roleEntity = roleManager.GetEntity(tmpid);
                    if (roleEntity.Code != null && roleEntity.Code.Equals(DefaultRole.Administrators.ToString()))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #14
0
        /// <summary>
        /// 获取用户实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public PiUserEntity GetEntity(UserInfo userInfo, string id)
        {
            PiUserEntity userEntity = null;
            //var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_GetEntity);
            //使用频率比较高,不用每次都做日志记录,提供效率
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                userEntity = new PiUserManager(dbProvider, userInfo).GetEntity(id);
                if (!string.IsNullOrEmpty(userEntity.RoleId))
                {
                    userEntity.RoleName = new PiRoleManager(dbProvider, userInfo).GetEntity(userEntity.RoleId).RealName;
                }
            });

            return(userEntity);
        }
        /// <summary>
        /// 用户添加之后执行的方法
        /// </summary>
        /// <param name="entity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        public void AfterAdd(PiUserEntity entity, out string statusCode)
        {
            var userLogOnEntity = new PiUserLogOnEntity
            {
                Id             = entity.Id,
                MultiUserLogin = SystemInfo.CheckOnLine ? 0 : 1,
                CheckIPAddress = SystemInfo.EnableCheckIPAddress ? 1 : 0
            };

            if (SystemInfo.EnableEncryptServerPassword)
            {
                userLogOnEntity.UserPassword = this.EncryptUserPassword(entity.UserPassword);
            }

            new PiUserLogOnManager(this.DBProvider, this.UserInfo).Add(userLogOnEntity);
            // 运行成功
            statusCode = StatusCode.OKAdd.ToString();
        }
Example #16
0
        /// <summary>
        /// 批量保存
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dataTable)
        {
            int          returnValue = 0;
            PiUserEntity userEntity  = new PiUserEntity();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                // 删除状态
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    string id = dataRow[PiUserTable.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        returnValue += this.Delete(id);
                    }
                }
                // 被修改过
                if (dataRow.RowState == DataRowState.Modified)
                {
                    string id = dataRow[PiUserTable.FieldId, DataRowVersion.Original].ToString();
                    if (!String.IsNullOrEmpty(id))
                    {
                        userEntity.GetFrom(dataRow);
                        returnValue += this.UpdateEntity(userEntity);
                    }
                }
                // 添加状态
                if (dataRow.RowState == DataRowState.Added)
                {
                    userEntity.GetFrom(dataRow);
                    returnValue += BusinessLogic.ConvertToNullableInt(this.AddEntity(userEntity)) > 0 ? 1 : 0;
                }
                if (dataRow.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dataRow.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            return(returnValue);
        }
Example #17
0
        public UserInfo ConvertToUserInfo(UserInfo userInfo, PiUserEntity userEntity, PiUserLogOnEntity userLogOnEntity = null)
        {
            userInfo.Id             = userEntity.Id;
            userInfo.Code           = userEntity.Code;
            userInfo.UserName       = userEntity.UserName;
            userInfo.RealName       = userEntity.RealName;
            userInfo.CompanyId      = userEntity.CompanyId;
            userInfo.CompanyName    = userEntity.CompanyName;
            userInfo.DepartmentId   = userEntity.DepartmentId;
            userInfo.DepartmentName = userEntity.DepartmentName;
            userInfo.WorkgroupId    = userEntity.WorkgroupId;
            userInfo.WorkgroupName  = userEntity.WorkgroupName;

            if (userLogOnEntity != null)
            {
                userInfo.OpenId = userLogOnEntity.OpenId;
            }

            if (userEntity.SecurityLevel == null)
            {
                userEntity.SecurityLevel = 0;
            }
            else
            {
                userInfo.SecurityLevel = (int)userEntity.SecurityLevel;
            }

            if (!string.IsNullOrEmpty(userEntity.RoleId))
            {
                // 获取角色名称
                var          roleManager = new PiRoleManager(DBProvider, UserInfo);
                PiRoleEntity roleEntity  = roleManager.GetEntity(userEntity.RoleId);
                if (!string.IsNullOrEmpty(roleEntity.Id))
                {
                    userInfo.RoleName = roleEntity.RealName;
                    userInfo.RoleId   = roleEntity.Id;
                }
            }
            return(userInfo);
        }
Example #18
0
        /// <summary>
        /// 激活帐户
        /// </summary>
        /// <param name="openId">唯一识别码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>用户实体</returns>
        public UserInfo AccountActivation(string openId, out string statusCode)
        {
            // 1.用户是否存在?
            UserInfo userInfo = null;

            // 用户没有找到状态
            statusCode = StatusCode.UserNotFound.ToString();
            // 检查是否有效的合法的参数
            if (!String.IsNullOrEmpty(openId))
            {
                PiUserManager userManager = new PiUserManager(DBProvider);
                // DataTable dataTable = userManager.GetDT(PiUserTable.FieldOpenId, openId, PiUserTable.FieldDeleteMark, 0);
                DataTable dataTable = userManager.GetDT(PiUserTable.FieldDeleteMark, 0);
                if (dataTable.Rows.Count == 1)
                {
                    //PiUserEntity userEntity = new PiUserEntity(dataTable);
                    PiUserEntity userEntity = BaseEntity.Create <PiUserEntity>(dataTable);
                    // 3.用户是否被锁定?
                    if (userEntity.Enabled == 0)
                    {
                        statusCode = StatusCode.UserLocked.ToString();
                        return(userInfo);
                    }
                    if (userEntity.Enabled == 1)
                    {
                        // 2.用户是否已经被激活?
                        statusCode = StatusCode.UserIsActivate.ToString();
                        return(userInfo);
                    }
                    if (userEntity.Enabled == -1)
                    {
                        // 4.成功激活用户
                        statusCode = StatusCode.OK.ToString();
                        userManager.SetProperty(PiUserTable.FieldId, userEntity.Id, PiUserTable.FieldEnabled, 1);
                        return(userInfo);
                    }
                }
            }
            return(userInfo);
        }
Example #19
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dbProvider">数据库连接</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string AddUser(IDbProvider dbProvider, UserInfo userInfo, PiUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            string returnValue = string.Empty;
            var    userManager = new PiUserManager(dbProvider, userInfo);

            returnValue   = userManager.Add(userEntity, out statusCode);
            statusMessage = userManager.GetStateMessage(statusCode);

            LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.UserService_AddUser, MethodBase.GetCurrentMethod());

            // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了
            if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString()))
            {
                // 不是系统管理员添加
                if (!userInfo.IsAdministrator)
                {
                    // 给超级管理员群组发信息
                    var      roleManager = new PiRoleManager(dbProvider, userInfo);
                    string[] roleIds     = roleManager.GetIds(PiRoleTable.FieldCode, "Administrators", PiRoleTable.FieldId);
                    string[] userIds     = userManager.GetIds(PiUserTable.FieldCode, "Administrator", PiUserTable.FieldId);
                    // 发送请求审核的信息
                    var messageEntity = new CiMessageEntity
                    {
                        Id           = BusinessLogic.NewGuid(),
                        FunctionCode = MessageFunction.WaitForAudit.ToString(),
                        ReceiverId   = DefaultRole.Administrator.ToString(),
                        MSGContent   = userInfo.RealName + "(" + userInfo.IPAddress + ")" + RDIFrameworkMessage.UserService_Application + userEntity.RealName + RDIFrameworkMessage.UserService_Check,
                        IsNew        = 1,
                        ReadCount    = 0,
                        Enabled      = 1,
                        DeleteMark   = 0
                    };

                    var messageManager = new CiMessageManager(dbProvider, userInfo);
                    messageManager.BatchSend(userIds, null, roleIds, messageEntity, false);
                }
            }
            return(returnValue);
        }
Example #20
0
        /// <summary>
        /// 扮演用户
        /// </summary>
        /// <param name="id">用户主键</param>
        /// <returns>用户类</returns>
        public UserInfo Impersonation(string id, out string statusCode)
        {
            UserInfo userInfo = null;
            // 获得登录信息
            PiUserLogOnEntity entity = new PiUserLogOnManager(this.DBProvider, this.UserInfo).GetEntity(id);

            // 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了
            if (!UserInfo.Id.Equals(id))
            {
                if (SystemInfo.CheckOnLine)
                {
                    if (entity.UserOnLine > 0)
                    {
                        statusCode = StatusCode.ErrorOnLine.ToString();
                        return(userInfo);
                    }
                }
            }

            PiUserEntity userEntity = this.GetEntity(id);

            userInfo = this.ConvertToUserInfo(userEntity);
            if (userEntity.IsStaff.Equals("1"))
            {
                // 获得员工的信息
                PiStaffEntity  staffEntity    = new PiStaffEntity();
                PiStaffManager staffManager   = new PiStaffManager(DBProvider, UserInfo);
                DataTable      dataTableStaff = staffManager.GetDTById(id);
                staffEntity.GetFrom(dataTableStaff);
                userInfo = staffManager.ConvertToUserInfo(staffEntity, userInfo);
            }
            statusCode = StatusCode.OK.ToString();
            // 登录、重新登录、扮演时的在线状态进行更新
            PiUserLogOnManager userLogOnManager = new PiUserLogOnManager(this.DBProvider, this.UserInfo);

            userLogOnManager.ChangeOnLine(id);
            return(userInfo);
        }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userEntity">实体</param>
        public string AddEntity(PiUserEntity userEntity)
        {
            string sequence = string.Empty;

            if (userEntity.SortCode == 0 || userEntity.SortCode == null)
            {
                CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                sequence            = sequenceManager.GetSequence(this.CurrentTableName, sequenceManager.DefaultSequence);
                userEntity.SortCode = int.Parse(sequence);
            }
            userEntity.QuickQuery = StringHelper.ToChineseSpell(userEntity.RealName);
            this.Identity         = false;
            SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, PiUserTable.FieldId);
            if (!this.Identity)
            {
                if (string.IsNullOrEmpty(userEntity.Id))
                {
                    sequence      = BusinessLogic.NewGuid();
                    userEntity.Id = sequence;
                }
                sqlBuilder.SetValue(PiUserTable.FieldId, userEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DBProvider.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(PiUserTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DBProvider.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(PiUserTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (userEntity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            userEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(PiUserTable.FieldId, userEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, userEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiUserTable.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiUserTable.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiUserTable.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiUserTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiUserTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiUserTable.FieldModifiedOn);
            if (DBProvider.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
Example #22
0
        /// <summary>
        /// 进行登录操作
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="openId">单点登录标识</param>
        /// <param name="createNewOpenId"></param>
        /// <param name="ipAddress">IP地址</param>
        /// <param name="macAddress">MAC地址</param>
        /// <param name="checkUserPassword">是否要检查用户密码</param>
        /// <returns>用户信息</returns>
        public UserInfo LogOn(string userName, string password, string openId = null, bool createNewOpenId = false, string ipAddress = null, string macAddress = null, bool checkUserPassword = true)
        {
            UserInfo userInfo = null;

            string realName = string.Empty;

            if (UserInfo != null)
            {
                realName = UserInfo.RealName;
                if (string.IsNullOrEmpty(ipAddress))
                {
                    ipAddress = UserInfo.IPAddress;
                }
                if (string.IsNullOrEmpty(macAddress))
                {
                    macAddress = UserInfo.MACAddress;
                }
            }

            PiUserLogOnManager userLogOnManager = new PiUserLogOnManager(this.DBProvider, this.UserInfo);

            // 01: 系统是否采用了在线用户的限制
            if (SystemInfo.OnLineLimit > 0 && userLogOnManager.CheckOnLineLimit())
            {
                this.ReturnStatusCode = StatusCode.ErrorOnLineLimit.ToString();
                // LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager,"LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress,RDIFrameworkMessage.MSG0089 + SystemInfo.OnLineLimit.ToString());
                return(userInfo);
            }

            // 02. 默认为用户没有找到状态,查找用户
            // 这是为了达到安全要求,不能提示用户未找到,那容易让别人猜测到帐户
            this.ReturnStatusCode = SystemInfo.EnableCheckPasswordStrength ? StatusCode.ErrorLogOn.ToString() : StatusCode.UserNotFound.ToString();

            // 03. 查询数据库中的用户数据?只查询未被删除的
            string[]  names     = { PiUserTable.FieldDeleteMark, PiUserTable.FieldUserName };
            Object[]  values    = { 0, userName };
            DataTable dataTable = this.GetDT(names, values);

            if (dataTable.Rows.Count == 0)
            {
                //TODO:若没数据再工号、邮件、手机号等方式登录
            }

            PiUserEntity      userEntity      = null;
            PiUserLogOnEntity userLogOnEntity = null;

            if (dataTable.Rows.Count > 1)
            {
                this.ReturnStatusCode = StatusCode.UserDuplicate.ToString();
            }
            else if (dataTable.Rows.Count == 1)
            {
                // 05. 判断密码,是否允许登录,是否离职是否正确
                userEntity = BaseEntity.Create <PiUserEntity>(dataTable.Rows[0]);
                if (!string.IsNullOrEmpty(userEntity.AuditStatus) && userEntity.AuditStatus.EndsWith(AuditStatus.WaitForAudit.ToString()))
                {
                    this.ReturnStatusCode = AuditStatus.WaitForAudit.ToString();
                    //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress, RDIFrameworkMessage.MSG0078);
                    return(userInfo);
                }

                // 用户无效、已离职的
                if (userEntity.IsDimission == 1 || userEntity.Enabled == 0)
                {
                    this.ReturnStatusCode = StatusCode.LogOnDeny.ToString();
                    return(userInfo);
                }

                // 用户是否有效的
                if (userEntity.Enabled == -1)
                {
                    this.ReturnStatusCode = StatusCode.UserNotActive.ToString();
                    //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress, RDIFrameworkMessage.MSG0080);
                    return(userInfo);
                }
                userLogOnEntity = userLogOnManager.GetEntity(userEntity.Id);
                if (string.IsNullOrEmpty(userEntity.UserName) || !userEntity.UserName.Equals("Administrator"))
                {
                    // 06. 允许登录时间是否有限制
                    if (userLogOnEntity.AllowEndTime != null)
                    {
                        userLogOnEntity.AllowEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogOnEntity.AllowEndTime.Value.Hour, userLogOnEntity.AllowEndTime.Value.Minute, userLogOnEntity.AllowEndTime.Value.Second);
                    }

                    if (userLogOnEntity.AllowStartTime != null)
                    {
                        userLogOnEntity.AllowStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogOnEntity.AllowStartTime.Value.Hour, userLogOnEntity.AllowStartTime.Value.Minute, userLogOnEntity.AllowStartTime.Value.Second);
                        if (DateTime.Now < userLogOnEntity.AllowStartTime)
                        {
                            this.ReturnStatusCode = StatusCode.UserLocked.ToString();
                            //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress, RDIFrameworkMessage.MSG0081 + userLogOnEntity.AllowStartTime.Value.ToString("HH:mm"));
                            return(userInfo);
                        }
                    }

                    if (userLogOnEntity.AllowEndTime != null)
                    {
                        if (DateTime.Now > userLogOnEntity.AllowEndTime)
                        {
                            this.ReturnStatusCode = StatusCode.UserLocked.ToString();
                            //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress, RDIFrameworkMessage.MSG0082 + userLogOnEntity.AllowEndTime.Value.ToString("HH:mm"));
                            return(userInfo);
                        }
                    }

                    // 07. 锁定日期是否有限制
                    if (userLogOnEntity.LockStartDate != null && DateTime.Now > userLogOnEntity.LockStartDate)
                    {
                        if (userLogOnEntity.LockEndDate == null || DateTime.Now < userLogOnEntity.LockEndDate)
                        {
                            this.ReturnStatusCode = StatusCode.UserLocked.ToString();
                            //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn",RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn,userName, ipAddress,RDIFrameworkMessage.MSG0083 + userLogOnEntity.LockStartDate.Value.ToString("yyyy-MM-dd"));
                            return(userInfo);
                        }
                    }

                    if (userLogOnEntity.LockEndDate != null && DateTime.Now < userLogOnEntity.LockEndDate)
                    {
                        this.ReturnStatusCode = StatusCode.UserLocked.ToString();
                        //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager,"LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress,RDIFrameworkMessage.MSG0084 + userEntity.LockEndDate.Value.ToString("yyyy-MM-dd"));
                        return(userInfo);
                    }
                }

                // 08. 是否检查用户IP地址,是否进行访问限制?管理员不检查IP. && !this.IsAdministrator(userEntity.Id.ToString()
                if (SystemInfo.EnableCheckIPAddress && userLogOnEntity.CheckIPAddress == 1 && (!(userEntity.UserName.Equals("Administrator") || userEntity.Code.Equals("Administrator"))))
                {
                    var parameterManager = new CiParameterManager(this.DBProvider);
                    var nameArr          = new string[2];
                    var valueArr         = new string[2];
                    nameArr[0]  = CiParameterTable.FieldParameterId;
                    nameArr[1]  = CiParameterTable.FieldCategoryKey;
                    valueArr[0] = userEntity.Id.ToString();
                    // 没有设置IP地址时不检查
                    valueArr[1] = "IPAddress";
                    if (!string.IsNullOrEmpty(ipAddress))
                    {
                        if (parameterManager.Exists(nameArr, valueArr))
                        {
                            if (!this.CheckIPAddress(ipAddress, userEntity.Id.ToString()))
                            {
                                var parameters = new List <KeyValuePair <string, object> >
                                {
                                    new KeyValuePair <string, object>(PiUserLogOnTable.FieldIPAddress, ipAddress)
                                };
                                //this.SetProperty(userEntity.Id, PiUserLogOnTable.FieldIPAddress, ipAddress);
                                this.ReturnStatusCode = StatusCode.ErrorIPAddress.ToString();
                                //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn",RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn,ipAddress, ipAddress, RDIFrameworkMessage.MSG0085);
                                return(userInfo);
                            }
                        }
                    }

                    // 没有设置MAC地址时不检查
                    valueArr[1] = "MacAddress";
                    if (!string.IsNullOrEmpty(macAddress))
                    {
                        if (parameterManager.Exists(nameArr, valueArr))
                        {
                            if (!this.CheckMacAddress(macAddress, userEntity.Id.ToString()))
                            {
                                this.ReturnStatusCode = StatusCode.ErrorMacAddress.ToString();
                                //this.SetProperty(userEntity.Id, PiUserLogOnTable.FieldMACAddress, macAddress);
                                //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn",RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn,macAddress, ipAddress, RDIFrameworkMessage.MSG0086);
                                return(userInfo);
                            }
                        }
                    }
                }

                // 10. 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了
                if ((UserInfo != null) && (!UserInfo.Id.Equals(userEntity.Id.ToString())))
                {
                    if (SystemInfo.CheckOnLine && userLogOnEntity.MultiUserLogin == 0 && userLogOnEntity.UserOnLine > 0)
                    {
                        // 自己是否登录了2次,在没下线的情况下
                        bool isSelf = false;
                        if (!string.IsNullOrEmpty(openId))
                        {
                            if (!string.IsNullOrEmpty(userLogOnEntity.OpenId))
                            {
                                if (userLogOnEntity.OpenId.Equals(openId))
                                {
                                    isSelf = true;
                                }
                            }
                        }
                        if (!isSelf)
                        {
                            this.ReturnStatusCode = StatusCode.ErrorOnLine.ToString();
                            //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn",RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn,userName, ipAddress, RDIFrameworkMessage.MSG0087);
                            return(userInfo);
                        }
                    }
                }

                // 04. 系统是否采用了密码加密策略?
                if (checkUserPassword && SystemInfo.EnableEncryptServerPassword)
                {
                    password = this.EncryptUserPassword(password);
                }


                // 11. 密码是否正确(null 与空看成是相等的)
                if (!(string.IsNullOrEmpty(userLogOnEntity.UserPassword) && string.IsNullOrEmpty(password)))
                {
                    bool userPasswordOK = true;
                    // 用户密码是空的
                    if (string.IsNullOrEmpty(userLogOnEntity.UserPassword))
                    {
                        // 但是输入了不为空的密码
                        if (!string.IsNullOrEmpty(password))
                        {
                            userPasswordOK = false;
                        }
                    }
                    else
                    {
                        // 用户的密码不为空,但是用户是输入了密码、 再判断用户的密码与输入的是否相同
                        userPasswordOK = !string.IsNullOrEmpty(password) && userLogOnEntity.UserPassword.Equals(password);
                    }
                    // 用户的密码不相等
                    if (!userPasswordOK)
                    {
                        userLogOnEntity.PasswordErrorCount = userLogOnEntity.PasswordErrorCount + 1;
                        if (SystemInfo.PasswordErrorLockLimit > 0 &&
                            userLogOnEntity.PasswordErrorCount >= SystemInfo.PasswordErrorLockLimit)

                        {
                            if (SystemInfo.PasswordErrorLockCycle == 0) //密码错误锁定周期若为0,直接设帐号无效,需要管理员审核
                            {
                                string[] names1  = { PiUserTable.FieldEnabled, PiUserTable.FieldAuditStatus };
                                object[] values1 = { "0", AuditStatus.WaitForAudit.ToString() };
                                this.SetProperty(userEntity.Id, names1, values1);
                            }
                            else
                            {
                                //进行帐号锁定
                                userLogOnEntity.LockStartDate = DateTime.Now;
                                userLogOnEntity.LockEndDate   = DateTime.Now.AddMinutes(SystemInfo.PasswordErrorLockCycle);
                                string[] names2  = { PiUserLogOnTable.FieldLockStartDate, PiUserLogOnTable.FieldLockEndDate };
                                object[] values2 = { userLogOnEntity.LockStartDate, userLogOnEntity.LockEndDate };
                                userLogOnManager.SetProperty(userEntity.Id, names2, values2);
                            }
                        }
                        else
                        {
                            userLogOnManager.SetProperty(userEntity.Id, PiUserLogOnTable.FieldPasswordErrorCount, userLogOnEntity.PasswordErrorCount);
                        }
                        //密码错误后处理:
                        //  11.1:记录日志
                        //LogManager.Instance.Add(DBProvider, userEntity.Id.ToString(), userEntity.RealName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userEntity.RealName, ipAddress, RDIFrameworkMessage.MSG0088);
                        // TODO: 11.2:看当天(24小时内)输入错误密码多少次了?
                        // TODO: 11.3:若输错密码数量已经超过了系统限制,则用户被锁定系统设定的小时数。
                        // TODO: 11.4:同时处理返回值,由于输入错误密码次数过多导致被锁定,登录时应读取这个状态比较,时间过期后应处理下状态。
                        // 密码强度检查,若是要有安全要求比较高的,返回的提醒消息要进行特殊处理,不能返回非常明确的提示信息。
                        this.ReturnStatusCode = SystemInfo.EnableCheckPasswordStrength ? StatusCode.ErrorLogOn.ToString() : StatusCode.PasswordError.ToString();
                        return(userInfo);
                    }
                }

                // 12. 更新IP地址,更新MAC地址
                userLogOnEntity.PasswordErrorCount = 0;
                if (!string.IsNullOrEmpty(ipAddress))
                {
                    userLogOnEntity.IPAddress = ipAddress;
                }
                if (!string.IsNullOrEmpty(macAddress))
                {
                    userLogOnEntity.MACAddress = macAddress;
                }
                userLogOnManager.SetProperty(userEntity.Id, new string[] { PiUserLogOnTable.FieldPasswordErrorCount, PiUserLogOnTable.FieldIPAddress, PiUserLogOnTable.FieldMACAddress }, new object[] { 0, ipAddress, macAddress });
                // 可以正常登录了
                this.ReturnStatusCode = StatusCode.OK.ToString();

                // 13. 登录、重新登录、扮演时的在线状态进行更新
                //userLogOnManager.ChangeOnLine(userEntity.Id);

                userInfo            = this.ConvertToUserInfo(userEntity, userLogOnEntity);
                userInfo.IPAddress  = ipAddress;
                userInfo.MACAddress = macAddress;
                userInfo.Password   = password;
                // 这里是判断用户是否为系统管理员的
                userInfo.IsAdministrator = IsAdministrator(userEntity);
                // 数据找到了,就可以退出循环了

                /*
                 * // 获得员工的信息
                 * if (userEntity.IsStaff == 1)
                 * {
                 *  PiStaffManager staffManager = new PiStaffManager(DBProvider, UserInfo);
                 *  //这里需要按 员工的用户ID来进行查找对应的员工-用户关系
                 *  PiStaffEntity staffEntity = new PiStaffEntity(staffManager.GetDT(PiStaffTable.FieldUserId, userEntity.Id));
                 *  if (!string.IsNullOrEmpty(staffEntity.Id))
                 *  {
                 *      userInfo = staffManager.ConvertToUserInfo(staffEntity, userInfo);
                 *  }
                 *
                 * }*/
            }

            // 14. 记录系统访问日志
            if (this.ReturnStatusCode == StatusCode.OK.ToString())
            {
                //LogManager.Instance.Add(DBProvider, userEntity.Id.ToString(), userEntity.RealName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userEntity.RealName, ipAddress, RDIFrameworkMessage.UserManager_LogOnSuccess);
                if (string.IsNullOrEmpty(userInfo.OpenId))
                {
                    createNewOpenId = true;
                }
                if (createNewOpenId)
                {
                    userInfo.OpenId = userLogOnManager.UpdateVisitDate(userEntity.Id.ToString(), createNewOpenId);
                }
                else
                {
                    userLogOnManager.UpdateVisitDate(userEntity.Id.ToString());
                }
            }
            else
            {
                //LogManager.Instance.Add(DBProvider, userName, realName, "LogOn", RDIFrameworkMessage.UserManager, "LogOn", RDIFrameworkMessage.UserManager_LogOn, userName, ipAddress, RDIFrameworkMessage.MSG0090);
            }
            return(userInfo);
        }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(PiUserEntity entity)
 {
     return(this.UpdateEntity(entity));
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(PiUserEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddEntity(entity));
 }
Example #25
0
        /// <summary>
        /// 进行密码验证
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>是否通过验证</returns>
        public bool ValidateUser(string userName, string password)
        {
            // 先按用户名登录
            var dt = this.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldUserName, userName)
                                , new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
                                , new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1));

            if (dt.Rows.Count == 0)
            {
                // 若没数据再按工号登录
                dt = this.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldCode, userName)
                                , new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
                                , new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1));

                if (dt.Rows.Count == 0)
                {
                    // 若没数据再按邮件登录
                    dt = this.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldEmail, userName)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1));
                }

                if (dt.Rows.Count == 0)
                {
                    // 若没数据再按手机号码登录
                    dt = this.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldMobile, userName)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1));
                }

                if (dt.Rows.Count == 0)
                {
                    // 若没数据再按手机号码登录
                    dt = this.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldTelephone, userName)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0)
                                    , new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1));
                }
            }

            PiUserEntity      userEntity      = null;
            PiUserLogOnEntity userLogOnEntity = null;
            var parameters = new List <KeyValuePair <string, object> >();

            if (dt.Rows.Count > 1)
            {
                return(false);
            }
            else if (dt.Rows.Count == 1)
            {
                // 05. 判断密码,是否允许登录,是否离职是否正确
                userEntity = BaseEntity.Create <PiUserEntity>(dt.Rows[0]);//new PiUserEntity(dt.Rows[0]);
                if (!string.IsNullOrEmpty(userEntity.AuditStatus) &&
                    userEntity.AuditStatus.EndsWith(AuditStatus.WaitForAudit.ToString()) &&
                    userLogOnEntity.PasswordErrorCount == 0)
                {
                    return(false);
                }
                PiUserLogOnManager userLogOnManager = new PiUserLogOnManager(this.DBProvider, this.UserInfo);
                userLogOnEntity = userLogOnManager.GetEntity(userEntity.Id);
                // 06. 允许登录时间是否有限制
                if (userLogOnEntity.AllowEndTime != null)
                {
                    userLogOnEntity.AllowEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogOnEntity.AllowEndTime.Value.Hour, userLogOnEntity.AllowEndTime.Value.Minute, userLogOnEntity.AllowEndTime.Value.Second);
                }
                if (userLogOnEntity.AllowStartTime != null)
                {
                    userLogOnEntity.AllowStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogOnEntity.AllowStartTime.Value.Hour, userLogOnEntity.AllowStartTime.Value.Minute, userLogOnEntity.AllowStartTime.Value.Second);
                    if (DateTime.Now < userLogOnEntity.AllowStartTime)
                    {
                        return(false);
                    }
                }
                if (userLogOnEntity.AllowEndTime != null)
                {
                    if (DateTime.Now > userLogOnEntity.AllowEndTime)
                    {
                        return(false);
                    }
                }

                // 07. 锁定日期是否有限制
                if (userLogOnEntity.LockStartDate != null)
                {
                    if (DateTime.Now > userLogOnEntity.LockStartDate)
                    {
                        if (userLogOnEntity.LockEndDate == null || DateTime.Now < userLogOnEntity.LockEndDate)
                        {
                            return(false);
                        }
                    }
                }
                if (userLogOnEntity.LockEndDate != null)
                {
                    if (DateTime.Now < userLogOnEntity.LockEndDate)
                    {
                        return(false);
                    }
                }

                // 03. 系统是否采用了密码加密策略?
                if (SystemInfo.EnableEncryptServerPassword)
                {
                    password = this.EncryptUserPassword(password);
                }

                // 11. 密码是否正确(null 与空看成是相等的)
                if (!(string.IsNullOrEmpty(userLogOnEntity.UserPassword) && string.IsNullOrEmpty(password)))
                {
                    bool userPasswordOK = true;
                    // 用户密码是空的
                    if (string.IsNullOrEmpty(userLogOnEntity.UserPassword))
                    {
                        // 但是输入了不为空的密码
                        if (!string.IsNullOrEmpty(password))
                        {
                            userPasswordOK = false;
                        }
                    }
                    else
                    {
                        // 用户的密码不为空,但是用户是输入了密码
                        userPasswordOK = !string.IsNullOrEmpty(password) && userLogOnEntity.UserPassword.Equals(password);
                    }
                    // 用户的密码不相等
                    if (!userPasswordOK)
                    {
                        // 这里更新用户连续输入错误密码次数
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #26
0
        public bool IsAdministrator(string userId)
        {
            PiUserEntity entity = this.GetEntity(userId);

            return(IsAdministrator(entity));
        }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>主键</returns>
 public string Add(PiUserEntity entity)
 {
     return(this.AddEntity(entity));
 }
Example #28
0
        public UserInfo ConvertToUserInfo(PiUserEntity userEntity, PiUserLogOnEntity userLogOnEntity = null)
        {
            var userInfo = new UserInfo();

            return(ConvertToUserInfo(userInfo, userEntity, userLogOnEntity));
        }