コード例 #1
0
ファイル: StaffService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 员工关联用户
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="staffId">员工主键</param>
        /// <param name="userId">用户主键</param>
        /// <returns>影响行数</returns>
        public int SetStaffUser(BaseUserInfo userInfo, string staffId, string userId)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseStaffManager(dbHelper, userInfo);
                if (string.IsNullOrEmpty(userId))
                {
                    result = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                }
                else
                {
                    // 一个用户只能帮定到一个帐户上,检查是否已经绑定过这个用户了。
                    string[] staffIds = manager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId), new KeyValuePair <string, object>(BaseStaffEntity.FieldDeletionStateCode, 0));
                    if (staffIds == null || staffIds.Length == 0)
                    {
                        result = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                        BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                        BaseUserEntity userEntity   = userManager.GetObject(userId);
                        result = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserName, userEntity.UserName));
                    }
                }
            });
            return(result);
        }
コード例 #2
0
        public string AddReceiver(string contactId, string receiverId)
        {
            string returnValue = string.Empty;

            // 需要判断是否存在
            if (this.Exists(new KeyValuePair <string, object>(BaseContactDetailsEntity.FieldContactId, contactId)
                            , new KeyValuePair <string, object>(BaseContactDetailsEntity.FieldReceiverId, receiverId)
                            , new KeyValuePair <string, object>(BaseContactDetailsEntity.FieldCategory, "User")))
            {
                return(string.Empty);
            }
            BaseUserManager          userManager          = new BaseUserManager(DbHelper, UserInfo);
            BaseUserEntity           useEntity            = userManager.GetObject(receiverId);
            BaseContactDetailsEntity contactDetailsEntity = new BaseContactDetailsEntity();

            // 这里一定要给个不可猜测的主键,为了提高安全性
            contactDetailsEntity.Id               = Guid.NewGuid().ToString("N");
            contactDetailsEntity.ContactId        = contactId;
            contactDetailsEntity.Category         = "User";
            contactDetailsEntity.ReceiverId       = useEntity.Id.ToString();
            contactDetailsEntity.ReceiverRealName = useEntity.RealName;
            contactDetailsEntity.IsNew            = 0;
            contactDetailsEntity.Enabled          = 1;
            contactDetailsEntity.NewComment       = 0;
            returnValue = this.Add(contactDetailsEntity);
            // 这里需要重新计算发送给了几个人,几个人已经阅读的功能
            this.SetReadState(contactId);
            return(returnValue);
        }
コード例 #3
0
        /// <summary>
        /// 某个用户是否对某个模块Url有访问权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="moduleUrl">模块Url</param>
        /// <returns>是否有权限</returns>
        public bool IsUrlAuthorizedByUser(BaseUserInfo userInfo, string userId, string moduleUrl)
        {
            bool result = false;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 是否超级管理员
                // 是超级管理员,就不用继续判断权限了
                var userManager           = new BaseUserManager(dbHelper, userInfo);
                BaseUserEntity userEntity = userManager.GetObject(userId);
                if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
                {
                    result = userManager.IsAdministrator(userId);
                    if (!result)
                    {
                        string tableName  = userInfo.SystemCode + "Module";
                        var moduleManager = new BaseModuleManager(dbHelper, userInfo, tableName);
                        List <BaseModuleEntity> entityList = null;
                        // moduleManager.GetList(userId);
                        // 这里需要改进,只读到第一个就可以返回了,没必要全部列表都计算一边
                        int count = entityList.Count(entity => !string.IsNullOrEmpty(entity.NavigateUrl) &&
                                                     (entity.NavigateUrl.Equals(moduleUrl, StringComparison.OrdinalIgnoreCase) || moduleUrl.StartsWith(entity.NavigateUrl)));
                        result = count > 0;
                    }
                }
            });

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// 更新数字签名密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public virtual int ChangeSignedPassword(string oldPassword, string newPassword, out string statusCode)
        {
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            #endif

            int result = 0;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    statusCode = Status.PasswordCanNotBeNull.ToString();
                    return(result);
                }
            }
            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                oldPassword = this.EncryptUserPassword(oldPassword);
                newPassword = this.EncryptUserPassword(newPassword);
            }
            // 判断输入原始密码是否正确
            BaseUserLogOnEntity entity = new BaseUserLogOnEntity();
            entity.GetSingle(this.GetDataTableById(UserInfo.Id));
            if (entity.SignedPassword == null)
            {
                entity.SignedPassword = string.Empty;
            }
            // 密码错误
            if (!entity.SignedPassword.Equals(oldPassword))
            {
                statusCode = Status.OldPasswordError.ToString();
                return(result);
            }
            // 更改密码
            result = this.SetProperty(UserInfo.Id, new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldSignedPassword, newPassword));
            if (result == 1)
            {
                statusCode = Status.ChangePasswordOK.ToString();
            }
            else
            {
                // 数据可能被删除
                statusCode = Status.ErrorDeleted.ToString();
            }

            // 写入调试信息
            #if (DEBUG)
            BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo);
            BaseUserEntity  userEntity  = userManager.GetObject(this.UserInfo.Id);
            int             milliEnd    = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")");
            #endif

            return(result);
        }
コード例 #5
0
        private int UpdataAuditStatr(string id, string categoryCode, string categoryFullName, string objectId, string objectFullName, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity)
        {
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(id);

            workFlowCurrentEntity.CategoryCode     = categoryCode;
            workFlowCurrentEntity.CategoryFullName = categoryFullName;
            workFlowCurrentEntity.ObjectId         = objectId;
            workFlowCurrentEntity.ObjectFullName   = objectFullName;
            workFlowCurrentEntity.ProcessId        = workFlowStepEntity.ProcessId;
            workFlowCurrentEntity.ActivityId       = workFlowStepEntity.Id;
            workFlowCurrentEntity.ActivityType     = workFlowStepEntity.ActivityType;
            workFlowCurrentEntity.SendDate         = DateTime.Now;
            workFlowCurrentEntity.AuditDate        = DateTime.Now;
            workFlowCurrentEntity.AuditStatus      = AuditStatus.StartAudit.ToString();
            workFlowCurrentEntity.AuditStatusName  = AuditStatus.StartAudit.ToDescription();

            // 是否提交给组织机构审批
            workFlowCurrentEntity.ToDepartmentId   = workFlowStepEntity.AuditDepartmentId;
            workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName;
            // 是否提交给角色审批
            workFlowCurrentEntity.ToRoleId       = workFlowStepEntity.AuditRoleId;
            workFlowCurrentEntity.ToRoleRealName = workFlowStepEntity.AuditRoleRealName;
            // 是否提交给用户审批
            workFlowCurrentEntity.ToUserId       = workFlowStepEntity.AuditUserId;
            workFlowCurrentEntity.ToUserRealName = workFlowStepEntity.AuditUserRealName;

            if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
            {
                BaseUserManager userManager = new BaseUserManager(UserInfo);
                BaseUserEntity  userEntity  = userManager.GetObject(workFlowStepEntity.AuditUserId);
                workFlowCurrentEntity.ToUserRealName = userEntity.RealName;
                // 用户的部门信息需要处理
                if (!string.IsNullOrEmpty(userEntity.DepartmentId))
                {
                    BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo);
                    BaseOrganizeEntity  entity          = organizeManager.GetObject(userEntity.DepartmentId);
                    workFlowCurrentEntity.ToDepartmentName = entity.FullName;
                }
            }
            // 当前审核人的信息写入当前工作流
            workFlowCurrentEntity.AuditUserId       = string.Empty;
            workFlowCurrentEntity.AuditUserCode     = string.Empty;
            workFlowCurrentEntity.AuditUserRealName = string.Empty;
            workFlowCurrentEntity.AuditIdea         = auditIdea;
            workFlowCurrentEntity.AuditDate         = DateTime.Now;

            int result = this.UpdateObject(workFlowCurrentEntity);

            this.AddHistory(workFlowCurrentEntity);
            return(result);
        }
コード例 #6
0
        /// <summary>
        /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的
        /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>用户信息</returns>
        private static BaseUserEntity SetCache(IRedisClient redisClient, string id)
        {
            BaseUserEntity result = null;

            BaseUserManager manager = new BaseUserManager();

            result = manager.GetObject(id);
            if (result != null)
            {
                SetCache(redisClient, result);
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// 替换当前步骤中的人员
        /// </summary>
        /// <param name="oldUserId">原来的工号</param>
        /// <param name="newUserId">新的工号</param>
        /// <returns>影响行数</returns>
        public int ReplaceUser(string oldUserId, string newUserId)
        {
            BaseUserManager userManager   = new BaseUserManager(this.UserInfo);
            BaseUserEntity  newUserEntity = userManager.GetObject(newUserId);
            SQLBuilder      sqlBuilder    = new SQLBuilder(this.DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldToUserId, newUserEntity.Id);
            sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldToUserRealName, newUserEntity.RealName);
            sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldToDepartmentId, newUserEntity.DepartmentId);
            sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldToDepartmentName, newUserEntity.DepartmentName);
            sqlBuilder.SetWhere(BaseWorkFlowCurrentEntity.FieldToUserId, oldUserId, "OldUserId");
            return(sqlBuilder.EndUpdate());
        }
コード例 #8
0
        /// <summary>
        /// 发送联络单
        /// </summary>
        /// <param name="contactId">联络单主键</param>
        /// <param name="receiverIds">接收者</param>
        /// <returns>影响行数</returns>
        public int Send(string contactId, string[] receiverIds)
        {
            int returnValue = 0;
            // 是否给自己发过这封邮件
            bool findSend = false;
            BaseContactDetailsManager contactDetailsManager = new BaseContactDetailsManager(DbHelper, UserInfo);
            BaseUserManager           userManager           = new BaseUserManager(DbHelper, UserInfo);
            BaseUserEntity            useEntity             = null;
            BaseContactDetailsEntity  contactDetailsEntity  = null;

            for (int i = 0; i < receiverIds.Length; i++)
            {
                useEntity = userManager.GetObject(receiverIds[i]);
                // 是有效的用户,而且是未必删除的用户才发邮件
                if (useEntity.Enabled == 1 && useEntity.DeletionStateCode == 0)
                {
                    contactDetailsEntity = new BaseContactDetailsEntity();
                    // 这里一定要给个不可猜测的主键,为了提高安全性
                    contactDetailsEntity.Id               = Guid.NewGuid().ToString("N");
                    contactDetailsEntity.ContactId        = contactId;
                    contactDetailsEntity.Category         = "User";
                    contactDetailsEntity.ReceiverId       = useEntity.Id.ToString();
                    contactDetailsEntity.ReceiverRealName = useEntity.RealName;
                    contactDetailsEntity.IsNew            = 1;
                    contactDetailsEntity.Enabled          = 1;
                    contactDetailsEntity.NewComment       = 0;
                    contactDetailsManager.Add(contactDetailsEntity, false);
                }
                // 若已经有发过,就不用再判断了
                if (!findSend)
                {
                    if (UserInfo.Id.Equals(receiverIds[i]))
                    {
                        findSend = true;
                    }
                }
                returnValue++;
            }
            // 没有给自己发过
            if (!findSend)
            {
                // 发送给自己一份
                this.Send(contactId);
                returnValue++;
            }
            // 设置总共发送了几个人
            this.SetProperty(new KeyValuePair <string, object>(BaseContactEntity.FieldId, contactId), new KeyValuePair <string, object>(BaseContactEntity.FieldSendCount, receiverIds.Length.ToString()));
            return(returnValue);
        }
コード例 #9
0
        /// <summary>
        /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>用户信息</returns>
        public static BaseUserEntity SetCache(string id)
        {
            BaseUserEntity result = null;

            BaseUserManager manager = new BaseUserManager();

            result = manager.GetObject(id);

            if (result != null)
            {
                SetCache(result);
            }

            return(result);
        }
コード例 #10
0
ファイル: UserService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 获取用户实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseUserEntity GetObject(BaseUserInfo userInfo, string id)
        {
            BaseUserEntity entity = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 判断是否已经登录的用户?
                if (userManager.UserIsLogOn(userInfo))
                {
                    entity = userManager.GetObject(id);
                }
            });
            return(entity);
        }
コード例 #11
0
        /// <summary>
        /// 发送给自己一份
        /// </summary>
        /// <param name="contactId">联络单主键</param>
        public string Send(string contactId)
        {
            BaseUserManager          userManager          = new BaseUserManager(DbHelper, UserInfo);
            BaseUserEntity           useEntity            = useEntity = userManager.GetObject(UserInfo.Id);
            BaseContactDetailsEntity contactDetailsEntity = new BaseContactDetailsEntity();

            // 这里一定要给个不可猜测的主键,为了提高安全性
            contactDetailsEntity.Id               = Guid.NewGuid().ToString("N");
            contactDetailsEntity.ContactId        = contactId;
            contactDetailsEntity.Category         = "User";
            contactDetailsEntity.ReceiverId       = useEntity.Id.ToString();
            contactDetailsEntity.ReceiverRealName = useEntity.RealName;
            contactDetailsEntity.IsNew            = 0;
            contactDetailsEntity.Enabled          = 1;
            contactDetailsEntity.NewComment       = 0;
            BaseContactDetailsManager contactDetailsManager = new BaseContactDetailsManager(DbHelper, UserInfo);

            return(contactDetailsManager.Add(contactDetailsEntity, false));
        }
コード例 #12
0
        /// <summary>
        /// 转发给别人看
        /// </summary>
        /// <param name="contactId">内部联络单主键</param>
        /// <param name="receiverIds">送给</param>
        /// <returns>影响行数</returns>
        public int AddReceivers(string contactId, string[] receiverIds)
        {
            int             returnValue = 0;
            BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo);
            BaseUserEntity  useEntity   = null;

            for (int i = 0; i < receiverIds.Length; i++)
            {
                if (!this.Exists(new KeyValuePair <string, object>(BaseContactDetailsEntity.FieldContactId, contactId)
                                 , new KeyValuePair <string, object>(BaseContactDetailsEntity.FieldReceiverId, receiverIds[i])))
                {
                    useEntity = userManager.GetObject(receiverIds[i]);
                    // 是有效的用户,而且是未必删除的用户才发邮件
                    if (useEntity.Enabled == 1 && useEntity.DeletionStateCode == 0)
                    {
                        this.AddReceiver(useEntity, contactId, receiverIds[i]);
                        returnValue++;
                    }
                }
            }
            // 这里需要重新计算发送给了几个人,几个人已经阅读的功能
            this.SetReadState(contactId);
            return(returnValue);
        }
コード例 #13
0
ファイル: MobileService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 忘记密码按手机号码获取
        /// </summary>
        /// <param name="applicationCode">应用编号</param>
        /// <param name="accountCode">账户</param>
        /// <param name="password">密码</param>
        /// <param name="userName">用户名</param>
        /// <param name="mobile">手机号码</param>
        /// <returns>成功</returns>
        public bool GetPasswordByMobile(BaseUserInfo userInfo, string userName, string mobile)
        {
            bool result = false;

            if (!string.IsNullOrEmpty(mobile))
            {
                BaseUserContactManager manager = new BaseUserContactManager();
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                if (!string.IsNullOrEmpty(mobile))
                {
                    parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldMobile, mobile));
                }
                // 手机号码重复不发验证码,防止把别人的密码给修改了
                DataTable dt = manager.GetDataTable(parameters);
                string    id = string.Empty;
                if (dt != null && dt.Rows.Count == 1)
                {
                    id = dt.Rows[0][BaseUserContactEntity.FieldId].ToString();
                }
                BaseUserManager userManager = null;
                if (!string.IsNullOrEmpty(id))
                {
                    userManager = new BaseUserManager();
                    bool           userNameOK = true;
                    BaseUserEntity userEntity = userManager.GetObject(id);
                    if (!string.IsNullOrEmpty(userName))
                    {
                        if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName))
                        {
                            userNameOK = false;
                            userInfo   = null;
                        }
                    }
                    // 只有有效的用户,才能获取密码,被删除的,无效的,不可以获取密码
                    if (userEntity.Enabled == 0 || userEntity.DeletionStateCode == 1)
                    {
                        userNameOK = false;
                        userInfo   = null;
                    }
                    if (userNameOK)
                    {
                        userInfo = userManager.ConvertToUserInfo(userEntity);
                    }
                    else
                    {
                        userInfo = null;
                    }
                }
                if (!string.IsNullOrEmpty(id) && userInfo != null)
                {
                    string userPassword = string.Empty;
                    if (BaseSystemInfo.CheckPasswordStrength)
                    {
                        userPassword = BaseRandom.GetRandomString(8).ToLower();
                    }
                    else
                    {
                        userPassword = BaseRandom.GetRandomString(8).ToLower();
                        // Random random = new System.Random();
                        // userPassword = random.Next(100000, 999999).ToString();
                    }
                    // 看是否有合理的请求参数
                    if (!string.IsNullOrEmpty(userPassword))
                    {
                        // 看是否一天超过了3次了
                        int sendUserPasswordCount = this.GetSendUserPasswordCount(mobile);
                        if (sendUserPasswordCount < 4)
                        {
                            // 应用编号
                            if (this.SendUserPassword(userInfo, mobile, userPassword))
                            {
                                userManager = new BaseUserManager(userInfo);
                                // 按手机号码获取的,可以自动解锁,防止密码连续输入错误,然后手机号码获取密码后,是被锁定状态,提高工作效率
                                userManager.SetPassword(userInfo.Id, userPassword, true);
                                userManager.GetStateMessage();
                                if (userManager.StatusCode == Status.SetPasswordOK.ToString())
                                {
                                    result = true;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #14
0
        /// <summary>
        /// 流程转发送给谁
        /// </summary>
        /// <param name="id">当前主键</param>
        /// <returns>影响行数</returns>
        private int StepAuditTransmit(string currentId, string workFlowCategory, string sendToId, string auditIdea)
        {
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId);

            // 1.记录当前的审核时间、审核人信息
            workFlowCurrentEntity.ToDepartmentId   = this.UserInfo.DepartmentId;
            workFlowCurrentEntity.ToDepartmentName = this.UserInfo.DepartmentName;
            workFlowCurrentEntity.ToUserId         = this.UserInfo.Id;
            workFlowCurrentEntity.ToUserRealName   = this.UserInfo.RealName;
            workFlowCurrentEntity.AuditStatus      = AuditStatus.Transmit.ToString();
            workFlowCurrentEntity.AuditStatusName  = AuditStatus.Transmit.ToDescription();

            // 2.记录审核日志
            this.AddHistory(workFlowCurrentEntity);

            // 3.上一个审核结束了,新的审核又开始了,更新待审核情况
            workFlowCurrentEntity.AuditUserId       = this.UserInfo.Id;
            workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName;
            workFlowCurrentEntity.AuditDate         = DateTime.Now;
            workFlowCurrentEntity.AuditIdea         = auditIdea;

            // 是否提交给部门审批
            if (workFlowCategory.Equals("ByOrganize"))
            {
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo);
                BaseOrganizeEntity  entity          = organizeManager.GetObject(sendToId);
                // 设置审批部门主键
                workFlowCurrentEntity.ToDepartmentId = sendToId;
                // 设置审批部门名称
                workFlowCurrentEntity.ToDepartmentName = entity.FullName;
            }
            // 是否提交给角色审批
            if (workFlowCategory.Equals("ByRole"))
            {
                BaseRoleManager roleManger = new BaseRoleManager(this.UserInfo);
                BaseRoleEntity  roleEntity = roleManger.GetObject(sendToId);
                // 设置审批角色主键
                workFlowCurrentEntity.ToRoleId = sendToId;
                // 设置审批角色名称
                workFlowCurrentEntity.ToRoleRealName = roleEntity.RealName;
            }
            // 是否提交给用户审批
            if (workFlowCategory.Equals("ByUser"))
            {
                BaseUserManager userManager = new BaseUserManager(UserInfo);
                BaseUserEntity  userEntity  = userManager.GetObject(sendToId);
                // 设置审批用户主键
                workFlowCurrentEntity.ToUserId = sendToId;
                // 设置审批用户名称
                workFlowCurrentEntity.ToUserRealName = userEntity.RealName;
                // TODO 用户的部门信息需要处理
                if (!string.IsNullOrEmpty(userEntity.DepartmentId))
                {
                    BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo);
                    BaseOrganizeEntity  entity          = organizeManager.GetObject(userEntity.DepartmentId);
                    workFlowCurrentEntity.ToDepartmentId   = userEntity.DepartmentId;
                    workFlowCurrentEntity.ToDepartmentName = entity.FullName;
                }
            }
            workFlowCurrentEntity.AuditStatus     = AuditStatus.WaitForAudit.ToString();
            workFlowCurrentEntity.AuditStatusName = AuditStatus.WaitForAudit.ToDescription();
            // 当前审核人的信息写入当前工作流
            workFlowCurrentEntity.Enabled           = 0;
            workFlowCurrentEntity.DeletionStateCode = 0;
            return(this.UpdateObject(workFlowCurrentEntity));
        }
コード例 #15
0
        /// <summary>
        /// 检查一个服务调用是否是允许调用的?
        /// 1:是否要记录日志?
        /// 2:是否需要埋点?检查性能?访问频率等?调用次数?
        /// 3:非合法的调用?是否日志记录?
        /// 4:异常的要进行处理?
        /// </summary>
        /// <param name="appKey">应用唯一标识</param>
        /// <param name="appSecret">应用的签名密钥</param>
        /// <param name="callLimit">是否进行限制</param>
        /// <param name="systemCode">访问子系统</param>
        /// <param name="permissionCode">判断的权限编号</param>
        /// <returns>验证情况</returns>
        public static BaseResult CheckService(string appKey, string appSecret, bool callLimit = false, string systemCode = "Base", string permissionCode = null)
        {
            BaseResult result = new DotNet.Utilities.BaseResult();

            result.Status = false;

            // AppKey: 23286115
            // AppSecret: c8d1f06f599d7370467993c72a34c701
            // permissionCode: "User.Add"

            string ipAddress = Utilities.GetIPAddress(true);

            // 1: 判断参数是否合理?目标服务,总不可以为空,否则怎么区别谁在调用这个服务了?
            if (string.IsNullOrEmpty(appKey))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "appKey为空、访问被拒绝";
                return(result);
            }

            // 2: 判断是否在接口角色里, 只有在接口角色里的,才可以进行远程调用,这样也方便把接口随时踢出来。
            string roleCode = "Interface";

            if (!BaseUserManager.IsInRoleByCache(systemCode, appKey, roleCode))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "非接口用户、访问被拒绝";
                return(result);
            }

            // 3: 判断调用的频率是否?这里需要高速判断,不能总走数据库?调用的效率要高,不能被远程接口给拖死了、自己的服务都不正常了。
            if (callLimit && PooledRedisHelper.CallLimit(appKey, 10, 10000))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "访问频率过高、访问被拒绝";
                return(result);
            }

            // 4: 判断签名是否有效?是否过期?可以支持多个签名,容易升级、容易兼容、容易有个过度的缓冲期。为了提高安全性,必须要有签名才对。
            if (!BaseServicesLicenseManager.CheckServiceByCache(appKey, appSecret))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "不合法签名、访问被拒绝";
                return(result);
            }

            // 5: 判断对方的ip是否合法的?1个服务程序,可以有多个ip。可以把服务当一个用户看待,一个目标用户可能也配置了多个服务,一般是远程连接。
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager();
            BaseUserLogOnEntity  userLogOnEntity  = userLogOnManager.GetObject(appKey);

            if (BaseUserManager.CheckIPAddressByCache(userLogOnEntity, ipAddress, true))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "不合法IP、访问被拒绝";
                return(result);
            }

            // 6: 判断是否有权限?防止被过渡调用,拖死数据库,可以用缓存的方式进行判断,这样不容易被客户端、合作伙伴拖垮。
            if (!string.IsNullOrEmpty(permissionCode) && !BasePermissionManager.IsAuthorizedByCache(systemCode, appKey, permissionCode))
            {
                result.StatusCode    = "AccessDeny";
                result.StatusMessage = "无权限 " + permissionCode + "、访问被拒绝";
                return(result);
            }

            // 7: 判断是否有效?判断时间是否对?
            BaseUserManager userManager     = new BaseUserManager();
            BaseUserEntity  userEntity      = userManager.GetObject(appKey);
            UserLogOnResult userLogOnResult = userManager.CheckUser(userEntity, userLogOnEntity);

            if (!string.IsNullOrEmpty(userLogOnResult.StatusCode))
            {
                BaseLoginLogManager.AddLog(systemCode, userEntity, ipAddress, string.Empty, string.Empty, userLogOnResult.StatusMessage);
                result.StatusCode    = userLogOnResult.StatusCode;
                result.StatusMessage = userLogOnResult.StatusMessage;
                return(result);
            }

            // 8:目前需要判断的,都加上了。
            result.Status = true;
            return(result);
        }
コード例 #16
0
        /// <summary>
        /// 忘记密码按电子邮件获取
        /// </summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userName">用户名</param>
        /// <param name="email">电子邮件</param>
        /// <returns>成功</returns>
        public bool GetPasswordByEmail(string taskId, BaseUserInfo userInfo, string userName, string email)
        {
            bool result = false;

            BaseUserContactManager manager = new BaseUserContactManager();
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            if (!string.IsNullOrEmpty(email))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email));
            }
            string id = manager.GetId(parameters);

            if (!string.IsNullOrEmpty(id))
            {
                BaseUserManager userManager = new BaseUserManager();
                bool            userNameOK  = true;
                BaseUserEntity  userEntity  = userManager.GetObject(id);
                if (!string.IsNullOrEmpty(userName))
                {
                    if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName))
                    {
                        userNameOK = false;
                        userInfo   = null;
                    }
                }
                if (userNameOK)
                {
                    userInfo = userManager.ConvertToUserInfo(userEntity);
                }
            }
            if (!string.IsNullOrEmpty(id))
            {
                string userPassword = string.Empty;
                if (BaseSystemInfo.CheckPasswordStrength)
                {
                    userPassword = BaseRandom.GetRandomString(8).ToLower();
                }
                else
                {
                    userPassword = BaseRandom.GetRandomString(8).ToLower();
                    // Random random = new System.Random();
                    // userPassword = random.Next(100000, 999999).ToString();
                }

                // 邮件内容
                SmtpClient smtpClient = new SmtpClient(BaseSystemInfo.MailServer);
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials           = new NetworkCredential(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword);
                // 指定如何处理待发的邮件
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                string mailTitle = BaseSystemInfo.SoftFullName + "忘记密码";

                string mailBody = "您的新密码为:" + userPassword + " " + System.Environment.NewLine
                                  + "<br/> " + System.Environment.NewLine + BaseSystemInfo.SoftFullName + "访问地址: http://www.zto.cn/";
                // 读取模板文件
                string file = BaseSystemInfo.StartupPath + "\\Forgot.Mail.txt";
                if (System.IO.File.Exists(file))
                {
                    mailBody = System.IO.File.ReadAllText(file, Encoding.UTF8);
                    mailBody = mailBody.Replace("{Realname}", userInfo.RealName);
                    mailBody = mailBody.Replace("{UserPassword}", userPassword);
                }
                // 发送邮件
                MailMessage mailMessage = new MailMessage(BaseSystemInfo.MailUserName, email, mailTitle, mailBody);
                mailMessage.BodyEncoding = Encoding.Default;
                mailMessage.IsBodyHtml   = true;
                smtpClient.Send(mailMessage);

                BaseUserManager userManager = new BaseUserManager(userInfo);
                userManager.SetPassword(userInfo.Id, userPassword);
                userManager.GetStateMessage();
                if (userManager.StatusCode == Status.SetPasswordOK.ToString())
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }

            return(result);
        }
コード例 #17
0
        /// <summary>
        /// 审核退回详细步骤
        /// </summary>
        /// <param name="currentId">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <param name="toUserId">发送给</param>
        /// <param name="activityId">退回到指定步骤</param>
        /// <returns>影响行数</returns>
        private BaseWorkFlowCurrentEntity StepAuditReject(string currentId, string auditIdea, string toUserId = null, string activityId = null)
        {
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId);

            // 1.记录审核时间、审核人
            workFlowCurrentEntity.AuditUserId       = this.UserInfo.Id;
            workFlowCurrentEntity.AuditUserCode     = this.UserInfo.Code;
            workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName;
            workFlowCurrentEntity.AuditStatus       = AuditStatus.AuditReject.ToString();
            workFlowCurrentEntity.AuditStatusName   = AuditStatus.AuditReject.ToDescription();
            workFlowCurrentEntity.AuditDate         = DateTime.Now;
            workFlowCurrentEntity.AuditIdea         = auditIdea;
            // 2.记录日志
            this.AddHistory(workFlowCurrentEntity);

            // 3.更新待审核情况,流程已经结束了
            workFlowCurrentEntity.ActivityId = null;
            if (!string.IsNullOrEmpty(activityId))
            {
                workFlowCurrentEntity.ActivityId = int.Parse(activityId);
                // 1:先看流程审核步骤里是否有这个记录
                BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                BaseWorkFlowStepEntity  workFlowStepEntity  = BaseEntity.Create <BaseWorkFlowStepEntity>(
                    workFlowStepManager.GetDataTable(
                        new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldActivityId, activityId)
                        , new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId)));
                if (workFlowStepEntity != null && workFlowStepEntity.Id != null)
                {
                    workFlowCurrentEntity.SortCode         = workFlowStepEntity.SortCode;
                    workFlowCurrentEntity.ToUserId         = workFlowStepEntity.AuditUserId;
                    workFlowCurrentEntity.ToUserRealName   = workFlowStepEntity.AuditUserRealName;
                    workFlowCurrentEntity.ToDepartmentId   = workFlowStepEntity.AuditDepartmentId;
                    workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName;
                    workFlowCurrentEntity.ToRoleId         = workFlowStepEntity.AuditRoleId;
                    workFlowCurrentEntity.ToRoleRealName   = workFlowStepEntity.AuditRoleRealName;
                    workFlowCurrentEntity.Description      = string.Format("从{0}退回到{1}", workFlowCurrentEntity.ActivityFullName, workFlowStepEntity.FullName);
                    workFlowCurrentEntity.ActivityCode     = workFlowStepEntity.Code;
                    workFlowCurrentEntity.ActivityFullName = workFlowStepEntity.FullName;
                }
                else
                {
                    // 2:若没在流程审核步骤里那就从定义里找
                    BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo);
                    BaseWorkFlowActivityEntity  workFlowActivityEntity  = workFlowActivityManager.GetObject(activityId);
                    workFlowCurrentEntity.SortCode         = workFlowActivityEntity.SortCode;
                    workFlowCurrentEntity.ToUserId         = workFlowActivityEntity.AuditUserId;
                    workFlowCurrentEntity.ToUserRealName   = workFlowActivityEntity.AuditUserRealName;
                    workFlowCurrentEntity.ToDepartmentId   = workFlowActivityEntity.AuditDepartmentId;
                    workFlowCurrentEntity.ToDepartmentName = workFlowActivityEntity.AuditDepartmentName;
                    workFlowCurrentEntity.ToRoleId         = workFlowActivityEntity.AuditRoleId;
                    workFlowCurrentEntity.ToRoleRealName   = workFlowActivityEntity.AuditRoleRealName;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(toUserId))
                {
                    BaseUserManager userManager = new BaseUserManager(UserInfo);
                    BaseUserEntity  userEntity  = userManager.GetObject(toUserId);
                    workFlowCurrentEntity.ToUserId         = userEntity.Id;
                    workFlowCurrentEntity.ToUserRealName   = userEntity.RealName;
                    workFlowCurrentEntity.ToDepartmentId   = userEntity.DepartmentId;
                    workFlowCurrentEntity.ToDepartmentName = userEntity.DepartmentName;
                    workFlowCurrentEntity.ToRoleId         = null;
                    workFlowCurrentEntity.ToRoleRealName   = null;
                }
                //workFlowCurrentEntity.SortCode = null;
            }
            workFlowCurrentEntity.SendDate = DateTime.Now;
            workFlowCurrentEntity.Enabled  = 0;
            // 4.生成审核结束的记录
            this.UpdateObject(workFlowCurrentEntity);
            return(workFlowCurrentEntity);
        }