JAVA全系列 教程
3762个小节阅读:7094.9k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在手机号验证码登录的方法中,存在一个小bug,即给用户发送登录验证码前,需要判断该手机是否注册过,状态是否正常。所以我们需要优化发送登录验证码的功能:
用户服务接口添加方法
xxxxxxxxxx
// 判断用户手机号是否存在,状态是否正常
void checkPhone(String phone);
重新该方法
xxxxxxxxxx
@Override
public void checkPhone(String phone) {
// 1.判断手机号是否存在
QueryWrapper<ShoppingUser> queryWrapper = new QueryWrapper();
queryWrapper.eq("phone",phone);
ShoppingUser shoppingUser = shoppingUserMapper.selectOne(queryWrapper);
if (shoppingUser == null){
throw new BusException(CodeEnum.LOGIN_NOPHONE_ERROR);
}
// 2.判断用户状态
if(!"Y".equals(shoppingUser.getStatus())){
throw new BusException(CodeEnum.LOGIN_NOPHONE_ERROR);
}
}
修改发送登录验证码控制器
xxxxxxxxxx
/**
* 发送登录短信验证码
* @param phone 手机号
* @return 操作结果
*/
@GetMapping("/sendLoginCheckCode")
public BaseResult sendLoginCheckCode(String phone){
// 1.判断该用户是否已经注册,状态是否正常
shoppingUserService.checkPhone(phone);
// 2.生成随机四位数验证码
String checkCode = RandomUtil.buildCheckCode(4);
// 3.发送短信
BaseResult result = messageService.sendMessage(phone, checkCode);
// 4.发送成功,将验证码保存到redis中,发送失败,返回发送结果
if (200 == result.getCode()){
shoppingUserService.saveLoginCheckCode(phone,checkCode);
return BaseResult.ok();
}else {
return result;
}
}