refactor: 增加初始密码提示修改功能

This commit is contained in:
CaptainB 2022-02-15 20:59:37 +08:00 committed by 刘瑞斌
parent 3a8ceba4f3
commit e3f1a731d6
7 changed files with 59 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.service.BaseDisplayService; import io.metersphere.service.BaseDisplayService;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -60,7 +61,11 @@ public class LoginController {
} }
} }
SecurityUtils.getSubject().getSession().setAttribute("authenticate", UserSource.LOCAL.name()); 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") @GetMapping(value = "/currentUser")

View File

@ -33,9 +33,12 @@ import io.metersphere.excel.listener.EasyExcelListener;
import io.metersphere.excel.listener.UserDataListener; import io.metersphere.excel.listener.UserDataListener;
import io.metersphere.excel.utils.EasyExcelExporter; import io.metersphere.excel.utils.EasyExcelExporter;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import io.metersphere.log.service.OperatingLogService;
import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDTO;
import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.OperatingLogRequest;
import io.metersphere.log.vo.system.SystemReference; import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.notice.domain.UserDetail; import io.metersphere.notice.domain.UserDetail;
import io.metersphere.security.MsUserToken; import io.metersphere.security.MsUserToken;
@ -94,6 +97,8 @@ public class UserService {
private ExtProjectMapper extProjectMapper; private ExtProjectMapper extProjectMapper;
@Resource @Resource
private ExtWorkspaceMapper extWorkspaceMapper; private ExtWorkspaceMapper extWorkspaceMapper;
@Resource
private OperatingLogService operatingLogService;
public List<UserDetail> queryTypeByIds(List<String> userIds) { public List<UserDetail> queryTypeByIds(List<String> userIds) {
return extUserMapper.queryTypeByIds(userIds); return extUserMapper.queryTypeByIds(userIds);
@ -1286,12 +1291,30 @@ public class UserService {
* 根据userId 获取 user 所属工作空间和所属工作项目 * 根据userId 获取 user 所属工作空间和所属工作项目
* @param userId * @param userId
*/ */
public Map<Object,Object> getWSAndProjectByUserId(String userId){ public Map<Object, Object> getWSAndProjectByUserId(String userId) {
Map<Object,Object>map = new HashMap<>(2); Map<Object, Object> map = new HashMap<>(2);
List<Project> projects = extProjectMapper.getProjectByUserId(userId); List<Project> projects = extProjectMapper.getProjectByUserId(userId);
List<Workspace> workspaces = extWorkspaceMapper.getWorkspaceByUserId(userId); List<Workspace> workspaces = extWorkspaceMapper.getWorkspaceByUserId(userId);
map.put("project",projects); map.put("project", projects);
map.put("workspace",workspaces); map.put("workspace", workspaces);
return map; return map;
} }
public boolean checkWhetherChangePasswordOrNot(LoginRequest request) {
List<OperatingLogDTO> 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;
}
} }

View File

@ -5,6 +5,13 @@
<component :is="licenseHeader"></component> <component :is="licenseHeader"></component>
</el-col> </el-col>
</el-row> </el-row>
<el-row v-if="changePassword">
<el-col>
<div class="change-password-tip">
{{ $t('commons.change_password_tips') }}
</div>
</el-col>
</el-row>
<el-row id="header-top" type="flex" justify="space-between" align="middle" v-if="isMenuShow"> <el-row id="header-top" type="flex" justify="space-between" align="middle" v-if="isMenuShow">
<el-col :span="12"> <el-col :span="12">
<img :src="'/display/file/logo'" class="logo" alt=""> <img :src="'/display/file/logo'" class="logo" alt="">
@ -60,6 +67,11 @@ export default {
isMenuShow: true, isMenuShow: true,
}; };
}, },
computed: {
changePassword() {
return JSON.parse(sessionStorage.getItem("changePassword"));
}
},
created() { created() {
this.initSessionTimer(); this.initSessionTimer();
if (!hasLicense()) { if (!hasLicense()) {
@ -262,4 +274,12 @@ export default {
line-height: 30px; line-height: 30px;
color: white; color: white;
} }
.change-password-tip {
height: 30px;
background: #e6a23c;
text-align: center;
line-height: 30px;
color: white;
}
</style> </style>

View File

@ -427,6 +427,7 @@ export default {
sync_other_info: "Copy other config", sync_other_info: "Copy other config",
delete_current_version: 'Current version', delete_current_version: 'Current version',
delete_all_version: 'All versions', delete_all_version: 'All versions',
change_password_tips: 'Your password is the initial system password, please change it as soon as possible'
}, },
login: { login: {
normal_Login: "Normal Login", normal_Login: "Normal Login",

View File

@ -429,6 +429,7 @@ export default {
sync_other_info: "复制以下信息到新版本", sync_other_info: "复制以下信息到新版本",
delete_current_version: '列表版本', delete_current_version: '列表版本',
delete_all_version: '全部版本', delete_all_version: '全部版本',
change_password_tips: '您的密码是系统初始密码,请尽快修改密码',
}, },
login: { login: {
normal_Login: "普通登录", normal_Login: "普通登录",

View File

@ -429,6 +429,7 @@ export default {
sync_other_info: "復製以下信息到新版本", sync_other_info: "復製以下信息到新版本",
delete_current_version: '列表版本', delete_current_version: '列表版本',
delete_all_version: '全部版本', delete_all_version: '全部版本',
change_password_tips: '您的密碼是系統初始密碼,請盡快修改密碼',
}, },
login: { login: {
normal_Login: "普通登錄", normal_Login: "普通登錄",

View File

@ -178,6 +178,8 @@ export default {
}); });
}, },
doLogin() { doLogin() {
//
sessionStorage.removeItem('changePassword');
let publicKey = localStorage.getItem("publicKey"); let publicKey = localStorage.getItem("publicKey");
let form = { let form = {
@ -189,6 +191,7 @@ export default {
this.result = this.$post(this.loginUrl, form, response => { this.result = this.$post(this.loginUrl, form, response => {
saveLocalStorage(response); saveLocalStorage(response);
sessionStorage.setItem('loginSuccess', 'true'); sessionStorage.setItem('loginSuccess', 'true');
sessionStorage.setItem('changePassword', response.message);
this.getLanguage(response.data.language); this.getLanguage(response.data.language);
// //
this.checkRedirectUrl(); this.checkRedirectUrl();