欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

毕业设计记录 day(2) 用户注册及邮箱发送

程序员文章站 2022-07-01 15:18:57
...

一、结果展示

1.1 用户注册成功

毕业设计记录 day(2) 用户注册及邮箱发送

1.2 邮箱验证码输入错误

毕业设计记录 day(2) 用户注册及邮箱发送

1.3 用户重复注册

毕业设计记录 day(2) 用户注册及邮箱发送

二、代码模块

2.1 用户注册

   @RequestMapping("/regist")
    public Result regist(@RequestParam("email")String email, @RequestParam("pass")String pass,@RequestParam("mvc")String myVerifyCode,@RequestParam("tvc")String testVerifyCode){
        User byEmailAndPass = userService.findByEmailAndPass(email, pass);
        if(byEmailAndPass != null){
            System.out.println("重复注册");
            return new Result(Msg.RepeatRegist);
        }
        //判断邮箱格式,也可以在前端判断
        if(!EmailUtil.JudgeEmail(email)){
            return new Result(Msg.EmailFormatError);
        }
        //判断验证码是否输入正确
        if(!testVerifyCode.equals(myVerifyCode)){
            //验证码输入错误,直接的返回对应信息
           return new Result(Msg.InputVerifyCodeError);
        }
        //将用户的邮箱和密码存储在数据库中
        User user = new User(email, pass);
        User save = userService.save(user);
        if(save == null){
            return new Result(Msg.RegistFailed);
        }else {
            return new Result(Msg.RegistSucess);
        }
    }

2.2邮箱发送验证码

@RestController
public class JavaMailController {
    @Autowired
    JavaMailSender javaMailSender;
    //模拟注册的用户发送邮箱验证码功能,会返回给前端
    @RequestMapping("/sendMail")
    public Result sendMail (@RequestParam("email")String email) throws MailException {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("aaa@qq.com");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("验证码");
        int i = new Random().nextInt(899999);
        int i1 = i + 10000;
        simpleMailMessage.setText("您的验证码是:" + i1);
        javaMailSender.send(simpleMailMessage);
        String str = i1 + "";
        System.out.println("邮箱验证码是" + str);
        return new Result(Msg.EmailSendSuccess,str);
    }
}

三、元数据

3.1 时间

  • 2019 12 24

3.2 任务

完成用户注册及邮箱验证后端代码的编写

相关标签: 毕业设计记录