feat: 修复重置密码bug

This commit is contained in:
landaiqing
2024-06-09 13:22:37 +08:00
parent d1fe7bd34b
commit 52c3645e3e
6 changed files with 29 additions and 14 deletions

View File

@@ -176,8 +176,8 @@ public class SchisandraAuthUserController {
String token = schisandraAuthUserDTO.getToken(); String token = schisandraAuthUserDTO.getToken();
Double deg = schisandraAuthUserDTO.getDeg(); Double deg = schisandraAuthUserDTO.getDeg();
CaptchaResult captchaResult = checkRouteCaptcha.checkCaptcha(token, deg); CaptchaResult captchaResult = checkRouteCaptcha.checkCaptcha(token, deg);
String key = redisUtil.buildKey(AUTH_PHONE_PREFIX, schisandraAuthUserDTO.getPhone());
if (captchaResult.getCode() == 0) { if (captchaResult.getCode() == 0) {
String key = redisUtil.buildKey(AUTH_PHONE_PREFIX, schisandraAuthUserDTO.getPhone());
if (redisUtil.exist(key)) { if (redisUtil.exist(key)) {
if (!Objects.equals(redisUtil.get(key), schisandraAuthUserDTO.getActiveCode())) { if (!Objects.equals(redisUtil.get(key), schisandraAuthUserDTO.getActiveCode())) {
return CaptchaResult.failWithCode("验证码错误,请重新验证"); return CaptchaResult.failWithCode("验证码错误,请重新验证");
@@ -204,11 +204,11 @@ public class SchisandraAuthUserController {
return CaptchaResult.failWithCode(); return CaptchaResult.failWithCode();
} }
} else { } else {
return CaptchaResult.fail(); return CaptchaResult.failWithCode();
} }
} else { } else {
return CaptchaResult.failWithCode("验证失败!"); return CaptchaResult.fail();
} }
} }
@@ -258,13 +258,13 @@ public class SchisandraAuthUserController {
} }
/** /**
* @description:找回密码 * @description: 找回密码
* @param: [schisandraAuthUserDTO] * @param: [schisandraAuthUserDTO]
* @return: com.schisandra.auth.common.entity.CaptchaResult * @return: com.schisandra.auth.common.entity.CaptchaResult
* @author zlg * @author zlg
* @date: 2024/6/9 0:46 * @date: 2024/6/9 0:46
*/ */
@PostMapping @PostMapping("findPassword")
public CaptchaResult findPassword(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) { public CaptchaResult findPassword(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
if (log.isInfoEnabled()) { if (log.isInfoEnabled()) {
log.info("UserController.findPassword.dto:{}", JSON.toJSONString(schisandraAuthUserDTO)); log.info("UserController.findPassword.dto:{}", JSON.toJSONString(schisandraAuthUserDTO));
@@ -287,7 +287,7 @@ public class SchisandraAuthUserController {
return CaptchaResult.failWithCode("该手机号未注册"); return CaptchaResult.failWithCode("该手机号未注册");
} }
if (schisandraAuthUserDomainService.findThePassword(schisandraAuthUserBO)) { if (schisandraAuthUserDomainService.findThePassword(schisandraAuthUserBO)) {
return CaptchaResult.ok(); return CaptchaResult.ok("重置成功!");
} else { } else {
return CaptchaResult.failWithCode("修改密码失败"); return CaptchaResult.failWithCode("修改密码失败");
} }

View File

@@ -4,7 +4,6 @@ import cn.dev33.satoken.stp.StpUtil;
import com.schisandra.auth.application.factory.OauthTypeHandlerFactory; import com.schisandra.auth.application.factory.OauthTypeHandlerFactory;
import com.schisandra.auth.application.handler.oauth.SchisandraOauthTypeHandler; import com.schisandra.auth.application.handler.oauth.SchisandraOauthTypeHandler;
import com.schisandra.auth.common.entity.Result; import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.common.redis.RedisUtil;
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService; import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -15,12 +14,14 @@ import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils; import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
/** /**
* ClassName:SchisandraOauthController * ClassName:SchisandraOauthController
@@ -82,10 +83,13 @@ public class SchisandraOauthController {
AuthResponse<AuthUser> authResponse = authRequest.login(callback); AuthResponse<AuthUser> authResponse = authRequest.login(callback);
AuthUser data = authResponse.getData(); AuthUser data = authResponse.getData();
AuthToken token = data.getToken(); AuthToken token = data.getToken();
if (token == null) {
return;
}
Result result = schisandraAuthUserDomainService.insertAuthUserByOauth(data, type); Result result = schisandraAuthUserDomainService.insertAuthUserByOauth(data, type);
if (result.getSuccess()){ if (result.getSuccess()) {
response.sendRedirect(url + "loading?token=" + token.getAccessToken() + "&userId=" + StpUtil.getLoginIdAsString()); response.sendRedirect(url + "loading?token=" + token.getAccessToken() + "&userId=" + StpUtil.getLoginIdAsString());
}else{ } else {
log.error("登录失败"); log.error("登录失败");
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 354 KiB

After

Width:  |  Height:  |  Size: 8.5 MiB

View File

@@ -84,8 +84,7 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
@Override @Override
public boolean findThePassword(SchisandraAuthUserBO schisandraAuthUserBO) { public boolean findThePassword(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO); SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
Integer count = schisandraAuthUserService.update(schisandraAuthUser); return schisandraAuthUserService.updateUserPasswordByPhone(schisandraAuthUser);
return count > 0;
} }
/** /**

View File

@@ -50,4 +50,6 @@ public interface SchisandraAuthUserService {
int insertAuthUserByOauth(SchisandraAuthUser schisandraAuthUser); int insertAuthUserByOauth(SchisandraAuthUser schisandraAuthUser);
boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser);
} }

View File

@@ -1,6 +1,7 @@
package com.schisandra.auth.infra.basic.service.impl; package com.schisandra.auth.infra.basic.service.impl;
import com.mybatisflex.core.update.UpdateChain;
import com.schisandra.auth.infra.basic.dao.SchisandraAuthUserDao; import com.schisandra.auth.infra.basic.dao.SchisandraAuthUserDao;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser; import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
import com.schisandra.auth.infra.basic.entity.table.SchisandraAuthUserTableDef; import com.schisandra.auth.infra.basic.entity.table.SchisandraAuthUserTableDef;
@@ -57,7 +58,7 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
} }
/** /**
* 修改数据 * 根据主键修改数据
* *
* @param schisandraAuthUser 实例对象 * @param schisandraAuthUser 实例对象
* @return 实例对象 * @return 实例对象
@@ -84,4 +85,13 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
return schisandraAuthUserDao.insert(schisandraAuthUser); return schisandraAuthUserDao.insert(schisandraAuthUser);
} }
@Override
public boolean updateUserPasswordByPhone(SchisandraAuthUser schisandraAuthUser) {
return UpdateChain.of(SchisandraAuthUser.class)
.set(SchisandraAuthUser::getPassword, schisandraAuthUser.getPassword())
.where(SchisandraAuthUser::getPhone).eq(schisandraAuthUser.getPhone())
.update();
}
} }