From e3f1a731d64fd1ba93f6c564f8847e6a0ac459ef Mon Sep 17 00:00:00 2001 From: CaptainB Date: Tue, 15 Feb 2022 20:59:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=AF=86=E7=A0=81=E6=8F=90=E7=A4=BA=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginController.java | 7 ++++- .../io/metersphere/service/UserService.java | 31 ++++++++++++++++--- frontend/src/business/App.vue | 20 ++++++++++++ frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + frontend/src/login/Login.vue | 3 ++ 7 files changed, 59 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/LoginController.java b/backend/src/main/java/io/metersphere/controller/LoginController.java index 335888549f..4a1e13676b 100644 --- a/backend/src/main/java/io/metersphere/controller/LoginController.java +++ b/backend/src/main/java/io/metersphere/controller/LoginController.java @@ -13,6 +13,7 @@ import io.metersphere.i18n.Translator; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.service.BaseDisplayService; import io.metersphere.service.UserService; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.context.i18n.LocaleContextHolder; @@ -60,7 +61,11 @@ public class LoginController { } } SecurityUtils.getSubject().getSession().setAttribute("authenticate", UserSource.LOCAL.name()); - return userService.login(request); + ResultHolder result = userService.login(request); + // 登录是否提示修改密码 + boolean changePassword = userService.checkWhetherChangePasswordOrNot(request); + result.setMessage(BooleanUtils.toStringTrueFalse(changePassword)); + return result; } @GetMapping(value = "/currentUser") diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 66d4eb41e1..cf767dcca0 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -33,9 +33,12 @@ import io.metersphere.excel.listener.EasyExcelListener; import io.metersphere.excel.listener.UserDataListener; import io.metersphere.excel.utils.EasyExcelExporter; import io.metersphere.i18n.Translator; +import io.metersphere.log.service.OperatingLogService; import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; +import io.metersphere.log.vo.OperatingLogDTO; import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.log.vo.OperatingLogRequest; import io.metersphere.log.vo.system.SystemReference; import io.metersphere.notice.domain.UserDetail; import io.metersphere.security.MsUserToken; @@ -94,6 +97,8 @@ public class UserService { private ExtProjectMapper extProjectMapper; @Resource private ExtWorkspaceMapper extWorkspaceMapper; + @Resource + private OperatingLogService operatingLogService; public List queryTypeByIds(List userIds) { return extUserMapper.queryTypeByIds(userIds); @@ -1286,12 +1291,30 @@ public class UserService { * 根据userId 获取 user 所属工作空间和所属工作项目 * @param userId */ - public Map getWSAndProjectByUserId(String userId){ - Mapmap = new HashMap<>(2); + public Map getWSAndProjectByUserId(String userId) { + Map map = new HashMap<>(2); List projects = extProjectMapper.getProjectByUserId(userId); List workspaces = extWorkspaceMapper.getWorkspaceByUserId(userId); - map.put("project",projects); - map.put("workspace",workspaces); + map.put("project", projects); + map.put("workspace", workspaces); return map; } + + public boolean checkWhetherChangePasswordOrNot(LoginRequest request) { + List list = operatingLogService.list(new OperatingLogRequest()); + // 首次登录需要提示 + if (CollectionUtils.isEmpty(list)) { + return true; + } + + // 升级之后 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; + } } diff --git a/frontend/src/business/App.vue b/frontend/src/business/App.vue index d500708e0b..2ac56bf148 100644 --- a/frontend/src/business/App.vue +++ b/frontend/src/business/App.vue @@ -5,6 +5,13 @@ + + +
+ {{ $t('commons.change_password_tips') }} +
+
+
@@ -60,6 +67,11 @@ export default { isMenuShow: true, }; }, + computed: { + changePassword() { + return JSON.parse(sessionStorage.getItem("changePassword")); + } + }, created() { this.initSessionTimer(); if (!hasLicense()) { @@ -262,4 +274,12 @@ export default { line-height: 30px; color: white; } + +.change-password-tip { + height: 30px; + background: #e6a23c; + text-align: center; + line-height: 30px; + color: white; +} diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index f291e37920..9215ca1b5d 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -427,6 +427,7 @@ export default { sync_other_info: "Copy other config", delete_current_version: 'Current version', delete_all_version: 'All versions', + change_password_tips: 'Your password is the initial system password, please change it as soon as possible' }, login: { normal_Login: "Normal Login", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 44481be48f..ae20335960 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -429,6 +429,7 @@ export default { sync_other_info: "复制以下信息到新版本", delete_current_version: '列表版本', delete_all_version: '全部版本', + change_password_tips: '您的密码是系统初始密码,请尽快修改密码', }, login: { normal_Login: "普通登录", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 542c96695d..941a6c2b8e 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -429,6 +429,7 @@ export default { sync_other_info: "復製以下信息到新版本", delete_current_version: '列表版本', delete_all_version: '全部版本', + change_password_tips: '您的密碼是系統初始密碼,請盡快修改密碼', }, login: { normal_Login: "普通登錄", diff --git a/frontend/src/login/Login.vue b/frontend/src/login/Login.vue index 3572ed20e0..879e03fabe 100644 --- a/frontend/src/login/Login.vue +++ b/frontend/src/login/Login.vue @@ -178,6 +178,8 @@ export default { }); }, doLogin() { + // 删除缓存 + sessionStorage.removeItem('changePassword'); let publicKey = localStorage.getItem("publicKey"); let form = { @@ -189,6 +191,7 @@ export default { this.result = this.$post(this.loginUrl, form, response => { saveLocalStorage(response); sessionStorage.setItem('loginSuccess', 'true'); + sessionStorage.setItem('changePassword', response.message); this.getLanguage(response.data.language); // 检查登录用户的权限 this.checkRedirectUrl();