feat: 找回密码和手机号登录
This commit is contained in:
@@ -128,7 +128,6 @@ public class SchisandraAuthUserController {
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public CaptchaResult login(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
|
||||
|
||||
if (schisandraAuthUserDTO.getDeg() == null && schisandraAuthUserDTO.getToken() == null) {
|
||||
return CaptchaResult.fail("验证失败!");
|
||||
}
|
||||
@@ -152,7 +151,7 @@ public class SchisandraAuthUserController {
|
||||
} else {
|
||||
StpUtil.login(result.getId());
|
||||
userInfoPersistence(result.getId());
|
||||
return CaptchaResult.ok(result);
|
||||
return CaptchaResult.ok(map);
|
||||
}
|
||||
} else {
|
||||
return CaptchaResult.failWithCode();
|
||||
@@ -162,6 +161,57 @@ public class SchisandraAuthUserController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 用户通过手机号验证码登录
|
||||
* @param: [schisandraAuthUserDTO]
|
||||
* @return: com.schisandra.auth.common.entity.CaptchaResult
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 0:54
|
||||
*/
|
||||
@PostMapping("loginByPhone")
|
||||
public CaptchaResult loginByPhone(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
|
||||
if (schisandraAuthUserDTO.getDeg() == null && schisandraAuthUserDTO.getToken() == null) {
|
||||
return CaptchaResult.fail("验证失败!");
|
||||
}
|
||||
String token = schisandraAuthUserDTO.getToken();
|
||||
Double deg = schisandraAuthUserDTO.getDeg();
|
||||
CaptchaResult captchaResult = checkRouteCaptcha.checkCaptcha(token, deg);
|
||||
String key = redisUtil.buildKey(AUTH_PHONE_PREFIX, schisandraAuthUserDTO.getPhone());
|
||||
if (captchaResult.getCode() == 0) {
|
||||
if (redisUtil.exist(key)) {
|
||||
if (!Objects.equals(redisUtil.get(key), schisandraAuthUserDTO.getActiveCode())) {
|
||||
return CaptchaResult.failWithCode("验证码错误,请重新验证");
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
|
||||
SchisandraAuthUserBO loginByPhone = schisandraAuthUserDomainService.loginByPhone(schisandraAuthUserBO);
|
||||
SchisandraAuthUserDTO result = SchisandraAuthUserDTOConverter.INSTANCE.convertBOToDTO(loginByPhone);
|
||||
map.put("user", result);
|
||||
if (loginByPhone != null) {
|
||||
if (StpUtil.isLogin(result.getId())) {
|
||||
StpUtil.logout(result.getId());
|
||||
StpUtil.login(result.getId());
|
||||
String userToken = StpUtil.getTokenValueByLoginId(result.getId());
|
||||
map.put("token", userToken);
|
||||
userInfoPersistence(result.getId());
|
||||
return CaptchaResult.ok(map);
|
||||
} else {
|
||||
StpUtil.login(result.getId());
|
||||
userInfoPersistence(result.getId());
|
||||
return CaptchaResult.ok(map);
|
||||
}
|
||||
} else {
|
||||
return CaptchaResult.failWithCode();
|
||||
}
|
||||
} else {
|
||||
return CaptchaResult.fail();
|
||||
}
|
||||
|
||||
} else {
|
||||
return CaptchaResult.failWithCode("验证失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 通过手机号判断用户是否注册过
|
||||
* @param: [phone]
|
||||
@@ -207,5 +257,47 @@ public class SchisandraAuthUserController {
|
||||
redisUtil.set(permissionKey, new Gson().toJson(permissionList));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description:找回密码
|
||||
* @param: [schisandraAuthUserDTO]
|
||||
* @return: com.schisandra.auth.common.entity.CaptchaResult
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 0:46
|
||||
*/
|
||||
@PostMapping
|
||||
public CaptchaResult findPassword(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("UserController.findPassword.dto:{}", JSON.toJSONString(schisandraAuthUserDTO));
|
||||
}
|
||||
if (schisandraAuthUserDTO.getPhone() == null) {
|
||||
log.error("UserController.register.phone is null");
|
||||
return null;
|
||||
}
|
||||
String token = schisandraAuthUserDTO.getToken();
|
||||
Double deg = schisandraAuthUserDTO.getDeg();
|
||||
CaptchaResult captchaResult = checkRouteCaptcha.checkCaptcha(token, deg);
|
||||
String key = redisUtil.buildKey(AUTH_PHONE_PREFIX, schisandraAuthUserDTO.getPhone());
|
||||
if (captchaResult.getCode() == 0) {
|
||||
if (redisUtil.exist(key)) {
|
||||
if (!Objects.equals(redisUtil.get(key), schisandraAuthUserDTO.getActiveCode())) {
|
||||
return CaptchaResult.failWithCode("验证码错误,请重新验证");
|
||||
}
|
||||
SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
|
||||
if (schisandraAuthUserDomainService.queryByPhone(schisandraAuthUserBO.getPhone()) == null) {
|
||||
return CaptchaResult.failWithCode("该手机号未注册");
|
||||
}
|
||||
if (schisandraAuthUserDomainService.findThePassword(schisandraAuthUserBO)) {
|
||||
return CaptchaResult.ok();
|
||||
} else {
|
||||
return CaptchaResult.failWithCode("修改密码失败");
|
||||
}
|
||||
} else {
|
||||
return CaptchaResult.failWithCode("验证码失效");
|
||||
}
|
||||
} else {
|
||||
return CaptchaResult.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -13,7 +13,14 @@ import me.zhyd.oauth.model.AuthUser;
|
||||
* @since 2024-05-23 20:00:28
|
||||
*/
|
||||
public interface SchisandraAuthUserDomainService {
|
||||
|
||||
/**
|
||||
* @description: 找回密码
|
||||
* @param: [schisandraAuthUserBO]
|
||||
* @return: boolean
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 1:00
|
||||
*/
|
||||
boolean findThePassword(SchisandraAuthUserBO schisandraAuthUserBO);
|
||||
|
||||
/**
|
||||
* @param schisandraAuthUserBO
|
||||
@@ -23,6 +30,7 @@ public interface SchisandraAuthUserDomainService {
|
||||
* @date 2024/3/21 23:14
|
||||
*/
|
||||
Boolean register(SchisandraAuthUserBO schisandraAuthUserBO);
|
||||
|
||||
/**
|
||||
* @description: 用户登录
|
||||
* @param: [schisandraAuthUserBO]
|
||||
@@ -32,6 +40,15 @@ public interface SchisandraAuthUserDomainService {
|
||||
*/
|
||||
SchisandraAuthUserBO login(SchisandraAuthUserBO schisandraAuthUserBO);
|
||||
|
||||
/**
|
||||
* @description: 通过手机号登录
|
||||
* @param: [schisandraAuthUserBO]
|
||||
* @return: com.schisandra.auth.domain.bo.SchisandraAuthUserBO
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 1:00
|
||||
*/
|
||||
SchisandraAuthUserBO loginByPhone(SchisandraAuthUserBO schisandraAuthUserBO);
|
||||
|
||||
/**
|
||||
* @param schisandraAuthUserBO
|
||||
* @return java.lang.Object
|
||||
|
@@ -73,6 +73,20 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
||||
@Resource
|
||||
private SchisandraAuthPermissionService schisandraAuthPermissionService;
|
||||
|
||||
/**
|
||||
* @description: 找回密码
|
||||
* @param: [schisandraAuthUserBO]
|
||||
* @return: boolean
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 1:01
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean findThePassword(SchisandraAuthUserBO schisandraAuthUserBO) {
|
||||
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
|
||||
Integer count = schisandraAuthUserService.update(schisandraAuthUser);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 注册用户
|
||||
@@ -125,6 +139,18 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description: 手机号验证码登录
|
||||
* @param: [schisandraAuthUserBO]
|
||||
* @return: com.schisandra.auth.domain.bo.SchisandraAuthUserBO
|
||||
* @author zlg
|
||||
* @date: 2024/6/9 1:01
|
||||
*/
|
||||
@Override
|
||||
public SchisandraAuthUserBO loginByPhone(SchisandraAuthUserBO schisandraAuthUserBO) {
|
||||
SchisandraAuthUser schisandraAuthUser = schisandraAuthUserService.queryByPhone(schisandraAuthUserBO.getUserName());
|
||||
return SchisandraAuthUserBOConverter.INSTANCE.convertEntityToBO(schisandraAuthUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schisandraAuthUserBO
|
||||
|
Reference in New Issue
Block a user