From 9d544a4f3e9f792701d5e7c6329bc9396d932f90 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 26 Oct 2022 18:55:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=99=BB=E5=BD=95=E5=90=8Eadmin?= =?UTF-8?q?=E5=BC=B1=E5=AF=86=E7=A0=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/controller/LoginController.java | 9 ++++++++- .../gateway/service/UserLoginService.java | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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; + } }