牛客项目的注册模块

1.访问注册页面

  • 点击顶部区域内的链接,打开注册页面。

在这里插入图片描述

2.提交注册数据

  • 通过表单提交数据。
  • 服务端验证账号是否已存在、邮箱是否已注册。
  • 服务端发送激活邮件。

service层:

//注册(如果返回的map为null就代表注册成功)
 public Map<String,Object> register(User user){
     Map<String,Object> map = new HashMap<>();
     //空值处理
     if (user == null){
         throw new IllegalArgumentException("参数不能为空");
     }
     if (StringUtils.isBlank(user.getUsername())){
         map.put("usernameMsg","账号不能为空!");
         return map;
     }
     if (StringUtils.isBlank(user.getPassword())){
         map.put("passwordMsg","密码不能为空!");
         return map;
     }
     if (StringUtils.isBlank(user.getEmail())){
         map.put("emailMsg","邮箱不能为空!");
         return map;
     }

     //验证账号(是否已存在)
     User u = userMapper.selectByName(user.getUsername());
     if (u != null){
         map.put("usernameMsg","该账号已存在!");
         return map;
     }

     //验证邮箱
     u = userMapper.selectByEmail(user.getEmail());
     if (u != null){
         map.put("emailMsg","该邮箱已被注册!");
         return map;
     }

     //注册用户
     user.setSalt(CommunityUtil.generateUUID().substring(0,5));
     user.setPassword(CommunityUtil.md5(user.getPassword() + user.getSalt()));
     user.setType(0);
     user.setStatus(0);
     user.setActivationCode(CommunityUtil.generateUUID());
     user.setHeaderUrl(String.format("http://images.nowcoder.com/head/0t.png",new Random().nextInt(1000)));
     user.setCreateTime(new Date());
     userMapper.insertUser(user);

     //激活邮件
     Context context = new Context();
     context.setVariable("email", user.getEmail());
     //http://localhost:8080/community/activation/101/code
     String url = domain + contextPath + "/activation/" + user.getId() + "/" + user.getActivationCode();
     context.setVariable("url",url);
     String content = templateEngine.process("/mail/activation", context);
     mailClient.sendMail(user.getEmail(),"激活账号",content);


     return map;
 }

在这里插入图片描述
controller层:

在这里插入图片描述
thymeleaf语法:
在这里插入图片描述

3.激活注册账号

  • 点击邮件中的链接,访问服务端的激活服务。

service层:

在这里插入图片描述

controller层:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值