예제 #1
0
        public IActionResult ChangePwd(ChangePwdDto changePwdDto)
        {
            changePwdDto.Email = changePwdDto.Email.Trim();
            //第一步 是否发送过短消息 查询最后一次发送短消息实体对象,验证是否超时
            EmailValidateCodeLog entity = _userService.GetEmailLog(changePwdDto.Email);

            if (entity != null)
            {
                if (SMSHelper.CheckTime(entity.CreateTime) > 30 * 60)
                {
                    return(Ok(new ResponseBody()
                    {
                        ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "验证码已过期"
                    }));
                }
                if (entity.ValidateCode == changePwdDto.Code)
                {
                    //修改密码
                    var reuslt = _userService.ChangePwdByEmail(changePwdDto.Email, changePwdDto.NewPassword);
                    if (reuslt)
                    {
                        return(Ok(new ResponseBody()
                        {
                            ResponseCode = ResponseCodeEnum.Success, ResponseMessage = "修改密码成功"
                        }));
                    }
                    return(Ok(new ResponseBody()
                    {
                        ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "修改密码失败"
                    }));
                }
                else
                {
                    return(Ok(new ResponseBody()
                    {
                        ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "验证码错误"
                    }));
                }
            }
            return(Ok(new ResponseBody()
            {
                ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "请求失败,请重新获取验证码"
            }));
        }
예제 #2
0
        public IActionResult SendCode(string email)
        {
            var reuslt = _userService.CheckEmail(email);

            if (reuslt)
            {
                //发送验证码
                var emailLog = _userService.GetEmailLog(email);
                if (emailLog != null)
                {
                    if (SMSHelper.CheckTime(emailLog.CreateTime) < 30)
                    {
                        return(Ok(new ResponseBody()
                        {
                            ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "邮箱已发送"
                        }));
                    }
                }
                string validateCode  = SMSHelper.GetValidateCode();
                var    IsSendSuccess = SMSHelper.SendMail(validateCode, email);
                EmailValidateCodeLog emailValidateCodeLog = new EmailValidateCodeLog()
                {
                    Email        = email,
                    Status       = IsSendSuccess ? "SUCCESS" : "FAIL",
                    ValidateCode = validateCode
                };
                _userService.CreateEmailLog(emailValidateCodeLog);
                return(Ok(new ResponseBody()
                {
                    ResponseCode = ResponseCodeEnum.Success, ResponseMessage = "邮件已发送"
                }));
            }
            return(Ok(new ResponseBody()
            {
                ResponseCode = ResponseCodeEnum.Fail, ResponseMessage = "邮箱尚未注册"
            }));
        }