refactor: 增加初始密码提示修改功能
This commit is contained in:
parent
3a8ceba4f3
commit
e3f1a731d6
|
@ -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")
|
||||
|
|
|
@ -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<UserDetail> queryTypeByIds(List<String> userIds) {
|
||||
return extUserMapper.queryTypeByIds(userIds);
|
||||
|
@ -1286,12 +1291,30 @@ public class UserService {
|
|||
* 根据userId 获取 user 所属工作空间和所属工作项目
|
||||
* @param userId
|
||||
*/
|
||||
public Map<Object,Object> getWSAndProjectByUserId(String userId){
|
||||
Map<Object,Object>map = new HashMap<>(2);
|
||||
public Map<Object, Object> getWSAndProjectByUserId(String userId) {
|
||||
Map<Object, Object> map = new HashMap<>(2);
|
||||
List<Project> projects = extProjectMapper.getProjectByUserId(userId);
|
||||
List<Workspace> 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<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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,13 @@
|
|||
<component :is="licenseHeader"></component>
|
||||
</el-col>
|
||||
</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-col :span="12">
|
||||
<img :src="'/display/file/logo'" class="logo" alt="">
|
||||
|
@ -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;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -429,6 +429,7 @@ export default {
|
|||
sync_other_info: "复制以下信息到新版本",
|
||||
delete_current_version: '列表版本',
|
||||
delete_all_version: '全部版本',
|
||||
change_password_tips: '您的密码是系统初始密码,请尽快修改密码',
|
||||
},
|
||||
login: {
|
||||
normal_Login: "普通登录",
|
||||
|
|
|
@ -429,6 +429,7 @@ export default {
|
|||
sync_other_info: "復製以下信息到新版本",
|
||||
delete_current_version: '列表版本',
|
||||
delete_all_version: '全部版本',
|
||||
change_password_tips: '您的密碼是系統初始密碼,請盡快修改密碼',
|
||||
},
|
||||
login: {
|
||||
normal_Login: "普通登錄",
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue