Exemplo n.º 1
0
        /// <summary>
        /// 用户修改密码
        /// </summary>
        /// <param name="taskId">任务标识</param>
        /// <param name="userInfo">用户</param>
        /// <param name="oldPassword">原始密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>影响行数</returns>
        public UserLogOnResult ChangePassword(string taskId, BaseUserInfo userInfo, string oldPassword, string newPassword)
        {
            UserLogOnResult result = null;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                // 事务开始
                // dbHelper.BeginTransaction();
                var userManager = new BaseUserManager(dbHelper, userInfo);
                result          = new UserLogOnResult();
                result.UserInfo = userManager.ChangePassword(userInfo.Id, oldPassword, newPassword);

                // 获取登录后信息
                // result.Message = BaseParameterManager.GetParameterByCache("BaseNotice", "System", "LogOn", "Message");
                // 获得状态消息
                result.StatusCode    = userManager.StatusCode;
                result.StatusMessage = userManager.GetStateMessage();
                // 事务提交
                // dbHelper.CommitTransaction();
            });

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 按用户名登录(LDAP专用)
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo LogOnByUserName(BaseUserInfo userInfo, string userName, out string statusCode, out string statusMessage)
        {
            var parameter = ServiceParameter.CreateWithLog(userInfo
                                                           , MethodBase.GetCurrentMethod());
            BaseUserInfo returnUserInfo = null;
            string       returnCode     = string.Empty;
            string       returnMessage  = string.Empty;

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                // 先侦测是否在线
                userLogOnManager.CheckOnLine();
                // 然后获取用户密码
                var userManager = new BaseUserManager(userInfo);
                // 是否从角色判断管理员
                userManager.CheckIsAdministrator    = true;
                BaseUserEntity userEntity           = userManager.GetByUserName(userName);
                BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id);
                string password = userLogOnEntity.UserPassword;
                // 再进行登录
                returnUserInfo = userManager.LogOnByUserName(userName, password, null, false, userInfo.IPAddress, userInfo.MACAddress, false);
                returnCode     = userManager.StatusCode;
                returnMessage  = userManager.GetStateMessage();
                // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                // BaseLogManager.Instance.Add(userInfo, this.serviceName, MethodBase.GetCurrentMethod());
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnUserInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 用户修改签名密码
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="oldPassword">原始密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>影响行数</returns>
        public int ChangeSignedPassword(BaseUserInfo userInfo, string oldPassword, string newPassword, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            statusCode    = string.Empty;
            statusMessage = string.Empty;
            int returnValue = 0;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    // 事务开始
                    // dbHelper.BeginTransaction();
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    returnValue = userManager.ChangeSignedPassword(oldPassword, newPassword, out statusCode);
                    // 获得状态消息
                    statusMessage = userManager.GetStateMessage(statusCode);
                    // 事务提交
                    // dbHelper.CommitTransaction();
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_ChangeSignedPassword, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    // 事务回滚
                    // dbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="ipAddress">IP地址</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo UserLogOn(BaseUserInfo userInfo, string userName, string password, bool createOpenId, out string returnStatusCode, out string returnStatusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            returnStatusCode    = StatusCode.DbError.ToString();
            returnStatusMessage = string.Empty;

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

            BaseUserInfo returnUserInfo = null;
            // statusCode = ServiceSecurityContext.Current.PrimaryIdentity.Name;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 先侦测是否在线
                    userManager.CheckOnLine();
                    // 再进行登录
                    returnUserInfo      = userManager.LogOn(userName, password, createOpenId);
                    returnStatusCode    = userManager.ReturnStatusCode;
                    returnStatusMessage = userManager.GetStateMessage(returnStatusCode);
                    // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                    // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnUserInfo);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="entity">用户实体</param>
        /// <param name="userLogonEntity">用户登录实体</param>
        /// <param name="userContactEntity">用户联系方式</param>
        /// <param name="status">状态</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string CreateUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity entity, BaseUserLogonEntity userLogonEntity, BaseUserContactEntity userContactEntity, out Status status, out string statusMessage)
        {
            var result = string.Empty;

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

            var userManager = new BaseUserManager(dbHelper, userInfo);
            result        = userManager.AddUser(entity, userLogonEntity);
            status        = userManager.Status;
            statusMessage = userManager.GetStateMessage();

            // 20140219 JiRiGaLa 添加成功的用户才增加联系方式
            if (!string.IsNullOrEmpty(result) && status == Status.OkAdd && userContactEntity != null)
            {
                // 添加联系方式
                userContactEntity.UserId = int.Parse(result);
                var userContactManager = new BaseUserContactManager(dbHelper, userInfo);
                userContactEntity.CompanyId = entity.CompanyId;
                userContactManager.Add(userContactEntity);
            }

            // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了
            if (entity.Enabled == 0 && status == Status.OkAdd)
            {
                // 不是系统管理员添加
                if (!BaseUserManager.IsAdministrator(userInfo.Id))
                {
                    // 给超级管理员群组发信息
                    var roleManager = new BaseRoleManager(dbHelper, userInfo);
                    var roleIds     = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators"));
                    var userIds     = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator"));
                    // 发送请求审核的信息
                    //var messageEntity = new BaseMessageEntity
                    //{
                    //    FunctionCode = MessageFunction.WaitForAudit.ToString(),

                    //    // Pcsky 2012.05.04 显示申请的用户名
                    //    Contents = userInfo.RealName + "(" + userInfo.IpAddress + ")" + AppMessage.UserServiceApplication + entity.UserName + AppMessage.UserServiceCheck
                    //};
                    //messageEntity.Contents = result.RealName + "(" + result.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check;

                    //var messageManager = new BaseMessageManager(dbHelper, userInfo);
                    //messageManager.BatchSend(userIds, null, roleIds, messageEntity, false);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 按用户名登录
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <param name="returnStatusCode">返回状态码</param>
        /// <param name="returnStatusMessage">返回状消息</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo LogOnByUserName(BaseUserInfo userInfo, string userName, out string returnStatusCode, out string returnStatusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            BaseUserInfo returnUserInfo = null;
            returnStatusCode    = string.Empty;
            returnStatusMessage = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 先侦测是否在线
                    userManager.CheckOnLine();
                    // 再进行登录
                    returnUserInfo      = userManager.LogOnByUserName(userName, userInfo.IPAddress, userInfo.MACAddress);
                    returnStatusCode    = userManager.ReturnStatusCode;
                    returnStatusMessage = userManager.GetStateMessage();
                    // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                    // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnUserInfo);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 设置用户密码
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">被设置的员工主键</param>
        /// <param name="password">新密码</param>
        /// <param name="returnStatusCode">返回状态码</param>
        /// <param name="returnStatusMessage">返回状消息</param>
        /// <returns>影响行数</returns>
        public int SetPassword(BaseUserInfo userInfo, string[] userIds, string password, out string returnStatusCode, out string returnStatusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            returnStatusCode    = string.Empty;
            returnStatusMessage = string.Empty;
            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_SetPassword, MethodBase.GetCurrentMethod());
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    returnValue      = userManager.BatchSetPassword(userIds, password);
                    returnStatusCode = userManager.ReturnStatusCode;
                    // 获得状态消息
                    returnStatusMessage = userManager.GetStateMessage(returnStatusCode);
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int UpdateUser(BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 调用方法,并且返回运行结果
                    returnValue   = userManager.Update(userEntity, out statusCode);
                    statusMessage = userManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_UpdateUser, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string AddUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            BaseSystemInfo.IsAuthorized(userInfo);
            #endif

            string          returnValue = string.Empty;
            BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
            // 若是系统需要用加密的密码,这里需要加密密码。
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                userEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword);
                // 安全通讯密码、交易密码也生成好
                userEntity.CommunicationPassword = userManager.EncryptUserPassword(userEntity.CommunicationPassword);
            }
            returnValue   = userManager.Add(userEntity, out statusCode);
            statusMessage = userManager.GetStateMessage(statusCode);
            // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了
            if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString()))
            {
                // 不是系统管理员添加
                if (!userInfo.IsAdministrator)
                {
                    // 给超级管理员群组发信息
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo);
                    string[]        roleIds     = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators"));
                    string[]        userIds     = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator"));
                    // 发送请求审核的信息
                    BaseMessageEntity messageEntity = new BaseMessageEntity();
                    messageEntity.FunctionCode = MessageFunction.WaitForAudit.ToString();

                    // Pcsky 2012.05.04 显示申请的用户名
                    messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.UserName + AppMessage.UserService_Check;
                    //messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check;

                    BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo);
                    messageManager.BatchSend(userIds, null, roleIds, messageEntity, false);
                }
            }
            return(returnValue);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="entity">用户实体</param>
        /// <param name="userContactEntity">用户联系方式实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int UpdateUser(BaseUserInfo userInfo, BaseUserEntity entity, BaseUserContactEntity userContactEntity, out string statusCode, out string statusMessage)
        {
            int result = 0;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 调用方法,并且返回运行结果,判断重复
                // result = userManager.Update(entity, out StatusCode);
                // 不判断重复直接更新
                if (entity != null)
                {
                    // 2015-12-09 吉日嘎拉 确认更新日志功能
                    result = userManager.Update(entity);
                    // 若是超级管理员,就是名字编号重复了,也应该能修改数据比较好,否则有些事情无法办理下去了,由于历史原因导致数据重复的什么的,也需要能修改才可以。
                    if (userInfo.IsAdministrator)
                    {
                        if (userManager.StatusCode == Status.ErrorUserExist.ToString() ||
                            userManager.StatusCode == Status.ErrorCodeExist.ToString())
                        {
                            result = userManager.UpdateObject(entity);
                        }
                    }
                }
                if (userContactEntity != null)
                {
                    var userContactManager = new BaseUserContactManager(dbHelper, userInfo);
                    userContactManager.SetObject(userContactEntity);
                }
                if (result == 1)
                {
                    userManager.StatusCode = Status.OKUpdate.ToString();
                    returnCode             = userManager.StatusCode;
                }
                userManager.StatusMessage = userManager.GetStateMessage(returnCode);
                // 更新员工信息
                if (entity != null)
                {
                    if (entity.IsStaff != null && entity.IsStaff > 0)
                    {
                        //BaseStaffManager staffManager = new BaseStaffManager(dbHelper, result);
                        //string staffId = staffManager.GetIdByUserId(entity.Id);
                        //if (!string.IsNullOrEmpty(staffId))
                        //{
                        //    BaseStaffEntity staffEntity = staffManager.GetObject(staffId);
                        //    staffEntity.Code = entity.Code;
                        //    staffEntity.Birthday = entity.Birthday;
                        //    staffEntity.Gender = entity.Gender;
                        //    staffEntity.UserName = entity.UserName;
                        //    staffEntity.RealName = entity.RealName;
                        //    staffEntity.QQ = entity.QQ;
                        //    staffEntity.Mobile = entity.Mobile;
                        //    staffEntity.Telephone = entity.Telephone;
                        //    staffEntity.Email = entity.Email;
                        //    staffEntity.CompanyId = entity.CompanyId;
                        //    staffEntity.SubCompanyId = entity.SubCompanyId;
                        //    staffEntity.DepartmentId = entity.DepartmentId;
                        //    staffEntity.WorkgroupId = entity.WorkgroupId;
                        //    staffManager.Update(staffEntity);
                        //}
                    }
                }
                returnCode    = userManager.StatusCode;
                returnMessage = userManager.StatusMessage;
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
Exemplo n.º 13
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)
        {
            var result = false;

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

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

            if (!string.IsNullOrEmpty(id))
            {
                var userManager = new BaseUserManager();
                var userNameOk  = true;
                var userEntity  = userManager.GetEntity(id);
                if (!string.IsNullOrEmpty(userName))
                {
                    if (!string.IsNullOrEmpty(userEntity.UserName) && !userEntity.UserName.Equals(userName, StringComparison.Ordinal))
                    {
                        userNameOk = false;
                        userInfo   = null;
                    }
                }
                if (userNameOk)
                {
                    userInfo = userManager.ConvertToUserInfo(userEntity);
                }
            }
            if (!string.IsNullOrEmpty(id))
            {
                var userPassword = string.Empty;
                if (BaseSystemInfo.CheckPasswordStrength)
                {
                    userPassword = RandomUtil.GetString(8).ToLower();
                }
                else
                {
                    userPassword = RandomUtil.GetString(8).ToLower();
                    // Random random = new System.Random();
                    // userPassword = random.Next(100000, 999999).ToString();
                }

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

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

                var mailBody = "您的新密码为:" + userPassword + " " + Environment.NewLine
                               + "<br/> " + Environment.NewLine + BaseSystemInfo.SoftFullName + "访问地址: http://www.wangcaisoft.com/";
                // 读取模板文件
                var 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);
                }
                // 发送邮件
                var mailMessage = new MailMessage(BaseSystemInfo.MailUserName, email, mailTitle, mailBody)
                {
                    BodyEncoding = Encoding.Default,
                    IsBodyHtml   = true
                };
                smtpClient.Send(mailMessage);

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

            return(result);
        }