发表于: 2019-08-29 23:05:47
1 726
今天完成的事情:写手机号注册逻辑.
@PostMapping("/signupPhone")
public String signupPhone(String phone) {
logger.info("send msg phone is [{}]", phone);
try {
usrService.getPhoneCode(phone);
logger.info("send msg success");
return "redirect:/signupPage";
} catch (IllegalArgumentException argE) {
logger.error(argE.getMessage());
logger.error("send msg known error");
return "redirect:errorPage";
} catch (Throwable t) {
logger.error(t.getMessage());
logger.error("send msg unknown error");
return "redirect:errorPage";
}
}
@Override
public Integer getPhoneCode(String phoneNumber,String code){
Integer num = 100000 + (int) (Math.random() * 900000);
code=num.toString();
redisTemplate.opsForValue().set(phoneNumber,code);
return AccountInfo.singlesend(phoneNumber,code);
}
@PostMapping("/signup")
public String signup(RedirectAttributes model, @Validated Usr usr, BindingResult error, String code) {
logger.info("signup : usr = [{}]", usr);
try {
usrService.matchPhoneCode(code, usr);
usrService.insert(usr, error);
logger.info("signup success");
return "redirect:/loginPage";
} catch (IllegalArgumentException argE) {
logger.error(argE.getMessage());
logger.error("signup parameters error");
Map json = ResponseBo.msg(argE.getMessage());
model.addFlashAttribute("json", json);
return "redirect:/signupPage";
} catch (Throwable t) {
logger.error(t.getMessage());
logger.error("signup unknown error");
Map json = ResponseBo.msg("Unknow.Exception");
model.addFlashAttribute("json", json);
return "redirect:errorPage";
}
}
@Override
public Boolean matchPhoneCode(String code,User user){
String matchCode=(String) redisTemplate.opsForValue().get(user.getPhone());
return code.equals(matchCode);
}
邮箱同理.
明天计划的事情:计划使用ajax发送验证码,所以学习一下ajax看看怎么使用ajax发送一个post请求.然后尽快结束任务7
遇到的问题:暂无
收获:无.
评论