コード例 #1
0
        /// <summary>
        /// 按部门获取用户列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="departmentId">部门主键</param>
        /// <param name="containChildren">含子部门</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByDepartment(BaseUserInfo userInfo, string departmentId, bool containChildren)
        {
            var dt = new DataTable(BaseUserEntity.CurrentTableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseUserManager(dbHelper, userInfo);
                if (string.IsNullOrEmpty(departmentId))
                {
                    dt = userManager.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0)
                                                  , 200, BaseUserEntity.FieldSortCode);
                }
                else
                {
                    if (containChildren)
                    {
                        dt = userManager.GetChildrenUserDataTable(departmentId);
                    }
                    else
                    {
                        dt = userManager.GetDataTableByDepartment(departmentId);
                    }
                }
                dt.TableName = BaseUserEntity.CurrentTableName;
            });
            return(dt);
        }
コード例 #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)
        {
            bool 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);
                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 = BaseEntity.Create <BaseUserEntity>(userManager.GetDataTable(parameters));
                // 判断是否为空的
                if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
                {
                    // 被锁定15分钟,不允许15分钟内登录,这时间是按服务器的时间来的。
                    var userLogOnManager = new BaseUserLogOnManager();
                    BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id);
                    userLogOnEntity.LockStartDate       = DateTime.Now;
                    userLogOnEntity.LockEndDate         = DateTime.Now.AddMinutes(BaseSystemInfo.PasswordErrorLockCycle);
                    result = userLogOnManager.UpdateObject(userLogOnEntity) > 0;
                }
            });

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 用户忘记密码,发送密码
        /// </summary>
        /// <param name="email">邮箱地址</param>
        /// <param name="status">状态</param>
        /// <param name="statusMessage">状态信息</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>成功发送密码</returns>
        public static bool ResetPassword(string email, out Status status, out string statusMessage, out string newPassword)
        {
            var result = false;

            // 1.用户是否找到?默认是未找到用户状态
            status        = Status.UserNotFound;
            statusMessage = "未找到对应的用户";
            newPassword   = RandomUtil.GetRandom(100000, 999999).ToString();

            var userContactManager = new BaseUserContactManager();
            var parameters         = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email)
            };
            var userContactEntity = BaseEntity.Create <BaseUserContactEntity>(userContactManager.GetDataTable(parameters));

            if (userContactEntity != null && userContactEntity.UserId > 0)
            {
                var userManager = new BaseUserManager();
                // 2.用户是否已被删除?
                parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserEntity.FieldId, userContactEntity.UserId),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0)
                };
                var userEntity = BaseEntity.Create <BaseUserEntity>(userManager.GetDataTable(parameters));
                // 是否已找到了此用户
                if (userEntity != null && userEntity.Id > 0)
                {
                    // 3.用户是否有效的?
                    if (userEntity.Enabled == 1)
                    {
                        if (userManager.SetPassword(userEntity.Id, newPassword) > 0)
                        {
                            result        = true;
                            status        = Status.Ok;
                            statusMessage = "新密码已发送到您的注册邮箱" + email + ",请注意查收。";
                        }
                        else
                        {
                            status        = Status.ErrorUpdate;
                            statusMessage = "更新数据库失败,请重试!";
                        }
                    }
                    else
                    {
                        if (userEntity.Enabled == 0)
                        {
                            status        = Status.UserLocked;
                            statusMessage = "用户被锁定,不允许重置密码。";
                        }
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// 用户忘记密码,发送密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="status">状态</param>
        /// <param name="statusMessage">状态信息</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>成功发送密码</returns>
        public static bool SendPassword(string userName, out Status status, out string statusMessage, out string newPassword)
        {
            var result = false;

            // 1.用户是否找到?默认是未找到用户状态
            status        = Status.UserNotFound;
            statusMessage = "用户未找到,请重新输入用户名。";
            newPassword   = RandomUtil.GetRandom(100000, 999999).ToString();

            var userManager = new BaseUserManager();
            // 2.用户是否已被删除?
            var parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName));
            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0));
            var userEntity = BaseEntity.Create <BaseUserEntity>(userManager.GetDataTable(parameters));

            // 是否已找到了此用户
            if (userEntity != null && userEntity.Id > 0)
            {
                // 3.用户是否有效的?
                if (userEntity.Enabled == 1)
                {
                    //if (!string.IsNullOrEmpty(userEntity.Email))
                    //{
                    //    // 5.重新产生随机密码?
                    //    // 6.发送邮件给用户?
                    //    // 7.重新设置用户密码?
                    //    result = SendPassword(userEntity);
                    //    status = Status.Ok.ToString();
                    //    statusMessage = "新密码已发送到您的注册邮箱" + userEntity.Email + "。";
                    //}
                    //else
                    //{
                    //    // 4.用户是否有邮件账户?
                    //    status = Status.UserNotEmail.ToString();
                    //    statusMessage = "用户没有电子邮件地址,无法从新设置密码,请您及时联系系统管理员。";
                    //}
                }
                else
                {
                    if (userEntity.Enabled == 0)
                    {
                        status        = Status.UserLocked;
                        statusMessage = "用户被锁定,不允许设置密码。";
                    }
                    else
                    {
                        status        = Status.UserNotActive;
                        statusMessage = "用户还未被激活,不允许设置密码。";
                    }
                }
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// 获取用户列表
        /// 当用户非常多时,不需要显示角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="showRole">显示角色</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, bool showRole = true)
        {
            var result = new DataTable(BaseUserEntity.CurrentTableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 这里是获取用户列表
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 获取允许登录列表
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldIsVisible, 1)
                };
                result = userManager.GetDataTable(parameters, BaseUserEntity.FieldSortCode);
                // 是否显示角色信息
                if (showRole)
                {
                    // 这里是获取角色列表
                    var tableName     = userInfo.SystemCode + "Role";
                    var roleManager   = new BaseRoleManager(dbHelper, userInfo, tableName);
                    var dataTableRole = roleManager.GetDataTable();
                    if (!result.Columns.Contains("RoleName"))
                    {
                        result.Columns.Add("RoleName");
                    }
                    // 友善的显示属于多个角色的功能
                    var roleName = string.Empty;
                    foreach (DataRow dr in result.Rows)
                    {
                        roleName = string.Empty;
                        // 获取所在角色
                        var roleIds = userManager.GetRoleIds(dr[BaseUserEntity.FieldId].ToString());
                        if (roleIds != null)
                        {
                            for (var i = 0; i < roleIds.Length; i++)
                            {
                                roleName = roleName + BaseUtil.GetProperty(dataTableRole, roleIds[i], BaseRoleEntity.FieldName) + " ";
                            }
                        }
                        // 设置角色的名称
                        if (!string.IsNullOrEmpty(roleName))
                        {
                            dr["RoleName"] = roleName;
                        }
                    }
                    result.AcceptChanges();
                }
                result.TableName = BaseUserEntity.CurrentTableName;
            });

            return(result);
        }
コード例 #6
0
ファイル: LogOnService.cs プロジェクト: DreamALittle/C-AccMVC
        /// <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);
        }
コード例 #7
0
ファイル: LogService.cs プロジェクト: DreamALittle/C-AccMVC
        /// <summary>
        /// 获取用户访问情况日志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetLogGeneral(BaseUserInfo userInfo)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            DataTable dataTable = new DataTable(BaseLogEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    if (userInfo.IsAdministrator)
                    {
                        dataTable = userManager.GetDataTable();
                    }
                    else
                    {
                        BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
                        string[] userIds = permissionScopeManager.GetUserIds(userInfo.Id, "Resource.ManagePermission");
                        dataTable = userManager.GetDataTableByIds(userIds);
                    }
                    dataTable.TableName = BaseLogEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogService_GetLogGeneral, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(dataTable);
        }
コード例 #8
0
ファイル: LogOnService.cs プロジェクト: DreamALittle/C-AccMVC
        /// <summary>
        /// 获得内部员工列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetStaffUserDT(BaseUserInfo userInfo)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            DataTable dataTable = new DataTable(BaseStaffEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    // 检查用户在线状态(服务器专用)
                    BaseUserManager userManager = new BaseUserManager(dbHelper);
                    userManager.CheckOnLine();
                    // 获取允许登录列表
                    List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldIsStaff, 1));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                    dataTable           = userManager.GetDataTable(parameters, BaseStaffEntity.FieldSortCode);
                    dataTable.TableName = BaseUserEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_GetStaffUserDT, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(dataTable);
        }
コード例 #9
0
ファイル: UserService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 按主键获取用户数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByIds(BaseUserInfo userInfo, string[] ids)
        {
            var result = new DataTable(BaseUserEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager         = new BaseUserManager(dbHelper, userInfo);
                result                  = userManager.GetDataTable(ids);
                result.TableName        = BaseUserEntity.TableName;
                result.DefaultView.Sort = BaseUserEntity.FieldSortCode;
            });

            return(result);
        }
コード例 #10
0
ファイル: RoleService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 按组织机构获取角色列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="showUser">显示用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByOrganize(BaseUserInfo userInfo, string organizeId, bool showUser = true)
        {
            var dt = new DataTable(BaseRoleEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Role";
                // 获得角色列表
                var manager = new BaseRoleManager(dbHelper, userInfo, tableName);
                dt          = manager.GetDataTableByOrganize(organizeId);
                BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo, tableName);
                if (showUser)
                {
                    DataTable dataTableUser = userManager.GetDataTable();
                    if (!dt.Columns.Contains("Users"))
                    {
                        dt.Columns.Add("Users");
                    }
                    // 友善的显示属于多个角色的功能
                    string userName = string.Empty;
                    foreach (DataRow dr in dt.Rows)
                    {
                        userName = string.Empty;
                        // 获取所在用户
                        string[] userIds = userManager.GetUserIdsInRoleId(userInfo.SystemCode, dr[BaseRoleEntity.FieldId].ToString());
                        if (userIds != null)
                        {
                            for (int i = 0; i < userIds.Length; i++)
                            {
                                userName = userName + BaseBusinessLogic.GetProperty(dataTableUser, userIds[i], BaseUserEntity.FieldRealName) + ", ";
                            }
                        }
                        if (!string.IsNullOrEmpty(userName))
                        {
                            userName = userName.Substring(0, userName.Length - 2);
                            // 设置用户的名称
                            dr["Users"] = userName;
                        }
                    }
                    dt.AcceptChanges();
                }
                dt.TableName = BaseRoleEntity.TableName;
            });
            return(dt);
        }
コード例 #11
0
ファイル: LogService.cs プロジェクト: DreamALittle/C-AccMVC
//        #region public DataTable GetLogGeneralForOnlineUser(BaseUserInfo userInfo) 获取用户访问情况日志
//        /// <summary>
//        /// 获取用户访问情况日志
//        /// </summary>
//        /// <param name="userInfo">用户</param>
//        /// <returns>数据表</returns>
//        public DataTable GetLogGeneralForOnlineUser(BaseUserInfo userInfo, bool UserOnLine)
//        {
//            // 写入调试信息
//             #if (DEBUG)
//            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
//            #endif

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

//            DataTable dataTable = new DataTable(BaseLogEntity.TableName);
//            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
//            {
//                BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
//                try
//                {
//                    dbHelper.Open(UserCenterDbConnection);
//                    if (userInfo.IsAdministrator)
//                    {
//                        dataTable = userManager.GetDataTable();
//                    }
//                    else
//                    {
//                        BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
//                        string[] userIds = permissionScopeManager.GetUserIds(userInfo.Id, "Resource.ManagePermission");
//                        dataTable = userManager.GetDataTableByIds(userIds,UserOnLine);
//                    }
//                    dataTable.TableName = BaseLogEntity.TableName;
//                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogService_GetLogGeneral, MethodBase.GetCurrentMethod());
//                }
//                catch (Exception ex)
//                {
//                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
//                    throw ex;
//                }
//                finally
//                {
//                    dbHelper.Close();
//                }
//            }

//            // 写入调试信息
//#if (DEBUG)
//            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
//#endif
//            return dataTable;
//        }
//        #endregion

        #region public DataTable ResetVisitInfo(BaseUserInfo userInfo, string[] ids) 重置用户访问情况
        /// <summary>
        /// 重置用户访问情况
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">日志主键</param>
        /// <returns>数据表</returns>
        public DataTable ResetVisitInfo(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            DataTable dataTable = new DataTable(BaseLogEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    dbHelper.BeginTransaction();
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 重置访问情况
                    userManager.ResetVisitInfo(ids);
                    // 获取列表
                    dataTable           = userManager.GetDataTable();
                    dataTable.TableName = BaseLogEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogService_ResetVisitInfo, MethodBase.GetCurrentMethod());
                    dbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    dbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(dataTable);
        }
コード例 #12
0
        /// <summary>
        /// 获取委托列表
        /// </summary>
        /// <param name="permissionCode">操作权限编号</param>
        /// <param name="userId">用户主键</param>
        /// <returns>数据表</returns>
        public DataTable GetAuthorizeDT(string systemCode, string permissionCode, string userId = null)
        {
            if (userId == null)
            {
                userId = this.UserInfo.Id;
            }
            // 获取别人委托我的列表
            string permissionId = string.Empty;

            permissionId = BaseModuleManager.GetIdByCodeByCache(systemCode, permissionCode);
            string tableName = systemCode + "PermissionScope";
            BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(this.UserInfo, tableName);

            string[] names = new string[] {
                BasePermissionScopeEntity.FieldDeletionStateCode
                , BasePermissionScopeEntity.FieldEnabled
                , BasePermissionScopeEntity.FieldResourceCategory
                , BasePermissionScopeEntity.FieldPermissionId
                , BasePermissionScopeEntity.FieldTargetCategory
                , BasePermissionScopeEntity.FieldTargetId
            };
            Object[] values = new Object[] { 0, 1, BaseUserEntity.TableName, permissionId, BaseUserEntity.TableName, userId };
            // 排除过期的,此方法有性能问题,已经放到后台的Sql中处理。 comment by zgl on 2011-10-27
            //var result = manager.GetDataTable(names, values);
            //for (int i = 0; i < result.Rows.Count; i++)
            //{
            //    if (!string.IsNullOrEmpty(result.Rows[i][BasePermissionScopeEntity.FieldEndDate].ToString()))
            //    {
            //        // 过期的不显示
            //        if (DateTime.Parse(result.Rows[i][BasePermissionScopeEntity.FieldEndDate].ToString()).Date < DateTime.Now.Date)
            //        {
            //            result.Rows.RemoveAt(i);
            //            // result 行数会减少
            //            i--;
            //        }
            //    }
            //}

            //排除过期的,已经放到后台的Sql中处理。
            var dt = permissionScopeManager.GetAuthoriedList(BaseUserEntity.TableName, permissionId, BaseUserEntity.TableName, userId);

            string[]        userIds     = BaseBusinessLogic.FieldToArray(dt, BasePermissionScopeEntity.FieldResourceId).Distinct <string>().Where(t => !string.IsNullOrEmpty(t)).ToArray();
            BaseUserManager userManager = new BaseUserManager(this.UserInfo);

            return(userManager.GetDataTable(userIds));
        }
コード例 #13
0
        public BaseUserInfo LogOnByOpenId(string openId, string ipAddress = null, string macAddress = null)
        {
            BaseUserInfo userInfo = null;

            // 用户没有找到状态
            this.ReturnStatusCode = StatusCode.UserNotFound.ToString();
            // 检查是否有效的合法的参数
            if (!String.IsNullOrEmpty(openId))
            {
                BaseUserManager userManager = new BaseUserManager(DbHelper);
                DataTable       dataTable   = userManager.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldOpenId, openId));
                if (dataTable.Rows.Count == 1)
                {
                    BaseUserEntity userEntity = new BaseUserEntity(dataTable);
                    userInfo = this.LogOn(userEntity.UserName, userEntity.UserPassword, false, ipAddress, macAddress, false);
                }
            }
            return(userInfo);
        }
コード例 #14
0
        /// <summary>
        /// 激活帐户
        /// </summary>
        /// <param name="openId">唯一识别码</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo AccountActivation(string openId)
        {
            // 1.用户是否存在?
            BaseUserInfo userInfo = null;

            // 用户没有找到状态
            StatusCode = Status.UserNotFound.ToString();
            // 检查是否有效的合法的参数
            if (!string.IsNullOrEmpty(openId))
            {
                var manager    = new BaseUserManager(DbHelper);
                var parameters = new List <KeyValuePair <string, object> >
                {
                    // parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldOpenId, openId));
                    new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0)
                };
                var dt = manager.GetDataTable(parameters);
                if (dt != null && dt.Rows.Count == 1)
                {
                    var entity = BaseEntity.Create <BaseUserEntity>(dt);
                    // 3.用户是否被锁定?
                    if (entity.Enabled == 0)
                    {
                        StatusCode = Status.UserLocked.ToString();
                        return(userInfo);
                    }
                    if (entity.Enabled == 1)
                    {
                        // 2.用户是否已经被激活?
                        StatusCode = Status.UserIsActivate.ToString();
                        return(userInfo);
                    }
                    if (entity.Enabled == -1)
                    {
                        // 4.成功激活用户
                        StatusCode = Status.Ok.ToString();
                        manager.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, entity.Id), new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                        return(userInfo);
                    }
                }
            }
            return(userInfo);
        }
コード例 #15
0
        /// <summary>
        /// 激活帐户
        /// </summary>
        /// <param name="openId">唯一识别码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo AccountActivation(string openId, out string statusCode)
        {
            // 1.用户是否存在?
            BaseUserInfo userInfo = null;

            // 用户没有找到状态
            statusCode = StatusCode.UserNotFound.ToString();
            // 检查是否有效的合法的参数
            if (!String.IsNullOrEmpty(openId))
            {
                BaseUserManager userManager = new BaseUserManager(DbHelper);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldOpenId, openId));
                parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                DataTable dataTable = userManager.GetDataTable(parameters);
                if (dataTable.Rows.Count == 1)
                {
                    BaseUserEntity userEntity = new BaseUserEntity(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(new KeyValuePair <string, object>(BaseUserEntity.FieldId, userEntity.Id), new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                        return(userInfo);
                    }
                }
            }
            return(userInfo);
        }
コード例 #16
0
ファイル: UserService.cs プロジェクト: DreamALittle/C-AccMVC
        /// <summary>
        /// 按主键获取用户列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByIds(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            DataTable dataTable = new DataTable(BaseStaffEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    dataTable           = userManager.GetDataTable(BaseUserEntity.FieldId, ids, BaseUserEntity.FieldSortCode);
                    dataTable.TableName = BaseUserEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_GetDataTableByIds, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(dataTable);
        }
コード例 #17
0
        /// <summary>
        /// 获得用户列表
        /// </summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetUserDT(string taskId, BaseUserInfo userInfo)
        {
            var result = new DataTable(BaseUserEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 检查用户在线状态(服务器专用)
                BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager();
                userLogOnManager.CheckOnLine();
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 获取允许登录列表
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                result           = userManager.GetDataTable(parameters, BaseUserEntity.FieldSortCode);
                result.TableName = BaseUserEntity.TableName;
            });

            return(result);
        }