Example #1
0
        /// <summary>
        /// 根据邮箱获取用户实体
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public BaseUserEntity GetEntityByEmail(string email)
        {
            BaseUserEntity userEntity = null;

            // 用户没有找到状态
            StatusCode    = Status.UserNotFound.ToString();
            StatusMessage = GetStateMessage(StatusCode);
            // 检查是否有效的合法的参数
            if (!string.IsNullOrEmpty(email) && ValidateUtil.IsEmail(email))
            {
                var userContactManager = new BaseUserContactManager();
                var parameters         = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email)
                };
                var id = userContactManager.GetId(parameters);
                if (!string.IsNullOrEmpty(id))
                {
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(BaseUserEntity.FieldId, id),
                        new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0),
                        new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1)
                    };
                    var dt = GetDataTable(parameters);
                    if (dt != null && dt.Rows.Count == 1)
                    {
                        userEntity = BaseEntity.Create <BaseUserEntity>(dt);
                    }
                }
            }

            return(userEntity);
        }
Example #2
0
        public BaseUserEntity GetObjectByEmail(string email)
        {
            BaseUserEntity userEntity = null;

            // 用户没有找到状态
            this.StatusCode    = Status.UserNotFound.ToString();
            this.StatusMessage = this.GetStateMessage(this.StatusCode);
            // 检查是否有效的合法的参数
            if (!String.IsNullOrEmpty(email) && ValidateUtil.IsEmail(email))
            {
                BaseUserContactManager userContactManager        = new BaseUserContactManager();
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseUserContactEntity.FieldEmail, email));
                string id = userContactManager.GetId(parameters);
                if (!string.IsNullOrEmpty(id))
                {
                    parameters = new List <KeyValuePair <string, object> >();
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldId, id));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                    var dt = this.GetDataTable(parameters);
                    if (dt.Rows.Count == 1)
                    {
                        userEntity = BaseEntity.Create <BaseUserEntity>(dt);
                    }
                }
            }

            return(userEntity);
        }
Example #3
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);
        }
Example #4
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);
        }