登出功能添加清空用户缓存逻辑

This commit is contained in:
macro
2024-04-18 10:01:42 +08:00
parent 03bcfa2e48
commit 215bc0e4fd
3 changed files with 16 additions and 1 deletions

View File

@@ -108,7 +108,8 @@ public class UmsAdminController {
@ApiOperation(value = "登出功能") @ApiOperation(value = "登出功能")
@RequestMapping(value = "/logout", method = RequestMethod.POST) @RequestMapping(value = "/logout", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public CommonResult logout() { public CommonResult logout(Principal principal) {
adminService.logout(principal.getName());
return CommonResult.success(null); return CommonResult.success(null);
} }

View File

@@ -89,4 +89,10 @@ public interface UmsAdminService {
* 获取缓存服务 * 获取缓存服务
*/ */
UmsAdminCacheService getCacheService(); UmsAdminCacheService getCacheService();
/**
* 登出功能
* @param username 用户名
*/
void logout(String username);
} }

View File

@@ -276,4 +276,12 @@ public class UmsAdminServiceImpl implements UmsAdminService {
public UmsAdminCacheService getCacheService() { public UmsAdminCacheService getCacheService() {
return SpringUtil.getBean(UmsAdminCacheService.class); return SpringUtil.getBean(UmsAdminCacheService.class);
} }
@Override
public void logout(String username) {
//清空缓存中的用户相关数据
UmsAdmin admin = getCacheService().getAdmin(username);
getCacheService().delAdmin(admin.getId());
getCacheService().delResourceList(admin.getId());
}
} }