mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 02:57:13 +08:00
feat: 禁止密码过期用户访问业务接口
This commit is contained in:
@@ -61,6 +61,8 @@ import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static top.continew.admin.system.enums.PasswordPolicyEnum.PASSWORD_EXPIRATION_DAYS;
|
||||
|
||||
/**
|
||||
* 登录业务实现
|
||||
*
|
||||
@@ -199,6 +201,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
loginUser.setPermissions(permissionService.listPermissionByUserId(userId));
|
||||
loginUser.setRoleCodes(permissionService.listRoleCodeByUserId(userId));
|
||||
loginUser.setRoles(roleService.listByUserId(userId));
|
||||
loginUser.setPasswordExpirationDays(optionService.getValueByCode2Int(PASSWORD_EXPIRATION_DAYS.name()));
|
||||
return LoginHelper.login(loginUser);
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,6 @@ import top.continew.starter.data.mybatis.plus.service.IService;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -90,14 +89,6 @@ public interface UserService extends BaseService<UserResp, UserDetailResp, UserQ
|
||||
*/
|
||||
void updatePassword(String oldPassword, String newPassword, Long id);
|
||||
|
||||
/**
|
||||
* 密码是否已过期
|
||||
*
|
||||
* @param pwdResetTime 上次重置密码时间
|
||||
* @return 是否过期
|
||||
*/
|
||||
boolean isPasswordExpired(LocalDateTime pwdResetTime);
|
||||
|
||||
/**
|
||||
* 修改手机号
|
||||
*
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
@@ -210,20 +211,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
baseMapper.updateById(user);
|
||||
// 保存历史密码
|
||||
userPasswordHistoryService.add(id, password, passwordRepetitionTimes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPasswordExpired(LocalDateTime pwdResetTime) {
|
||||
// 永久有效
|
||||
int passwordExpirationDays = optionService.getValueByCode2Int(PASSWORD_EXPIRATION_DAYS.name());
|
||||
if (passwordExpirationDays <= SysConstants.NO) {
|
||||
return false;
|
||||
}
|
||||
// 初始密码也提示修改
|
||||
if (pwdResetTime == null) {
|
||||
return true;
|
||||
}
|
||||
return pwdResetTime.plusDays(passwordExpirationDays).isBefore(LocalDateTime.now());
|
||||
// 修改后登出
|
||||
StpUtil.logout();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user