diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java b/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java index 32b782934d..b0734fa9be 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/controller/LoginController.java @@ -11,6 +11,7 @@ import io.metersphere.gateway.service.BaseDisplayService; import io.metersphere.gateway.service.SystemParameterService; import io.metersphere.gateway.service.UserLoginService; import io.metersphere.request.LoginRequest; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.http.HttpStatus; @@ -71,7 +72,13 @@ public class LoginController { return Mono.defer(() -> userLoginService.login(request, session, locale).map(Mono::just).orElseGet(Mono::empty)) .subscribeOn(Schedulers.boundedElastic()) .switchIfEmpty(Mono.error(new ResponseStatusException(HttpStatus.BAD_REQUEST, "Not found user info or invalid password"))) - .map(ResultHolder::success); + .map(ResultHolder::success) + .map(rh -> { + // 登录是否提示修改密码 + boolean changePassword = userLoginService.checkWhetherChangePasswordOrNot(request); + rh.setMessage(BooleanUtils.toStringTrueFalse(changePassword)); + return rh; + }); } @GetMapping(value = "/currentUser") diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java b/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java index b81ce90df6..480485da8b 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/service/UserLoginService.java @@ -426,4 +426,16 @@ public class UserLoginService { throw new RuntimeException("Please check csrf token."); } } + + public boolean checkWhetherChangePasswordOrNot(LoginRequest request) { + // 升级之后 admin 还使用弱密码也提示修改 + if (StringUtils.equals("admin", request.getUsername())) { + UserExample example = new UserExample(); + example.createCriteria().andIdEqualTo("admin") + .andPasswordEqualTo(CodingUtil.md5("metersphere")); + return userMapper.countByExample(example) > 0; + } + + return false; + } }