java - 在 Angular 中注销用户并由管理员终止会话
问题描述
我需要在我的 Angular 应用程序中具有一项功能,管理员可以通过该功能注销并终止登录到系统的用户的会话。我的后端基于带有自定义身份验证的 Spring Boot RESTful API。如何在使用 Angular 时手动注销当前登录的用户并终止他们的会话?
我有一个控制器可以更改数据库中用户表的“logged_in”列中的标志。但是,这不会根据需要注销用户或终止他们的会话,而是注销当前用户(管理员)而不是登录的其他用户。
我进行 API 调用的角度代码:
this.apiService.LogUserOut(this.userProfile).subscribe(res => {
this.blockUI.stop();
this.response = res;
// end user session
this.authService.logout(this.userProfile.username).subscribe(data => {});
this.router.navigate(['/auth']);
this.globalService.setAuth(false);
localStorage.removeItem('otc');
});
控制器端点:
// logout a logged-in user
@PostMapping(value = "/sysusers/logUserOut")
public ResponseEntity<?> LogUserOut(@RequestBody User user) throws
Exception {
System.out.println("User logged out: " + user.getUsername());
userService.SetUserLoggedOut(user.getUsername());
return new ResponseEntity<>(new
CustomResponse(CustomResponse.APIV, 201, true, "You have logged the user
out"), HttpStatus.OK);
}
我希望系统过滤并检查用户是否登录,这样当管理员注销用户时,系统能够通知,否则系统应该注销用户。我知道如何注销当前用户,但不知道如何强制注销其他用户,因此将不胜感激。谢谢。
解决方案
推荐阅读
- java - 生成java方法
- java - Appium:尝试在 IOS 设备上安装应用程序时出错
- python - Matplotlib:未保存背景颜色
- javascript - AJAX POST 请求是发送 JS 代码,而不是一个动作
- javascript - 在 XML HttpRequest POST 请求后设置新的 GET XMLHttpRequest() onload 函数并传递数据
- haskell - 定义与此 Haskell 函数等效的尾递归函数
- reactjs - 既找不到样式组件的秘密内部结构
- optaplanner - addProblemFactChange() 在“退出 neverEnding 选择器 (..) 以避免无限循环”后停止工作。
- android - 在房间数据库android中删除行
- c# - C# 使用蓝牙发送 AT 命令