首页 > 解决方案 > 在 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);
} 

我希望系统过滤并检查用户是否登录,这样当管理员注销用户时,系统能够通知,否则系统应该注销用户。我知道如何注销当前用户,但不知道如何强制注销其他用户,因此将不胜感激。谢谢。

标签: javaangulartypescriptspring-boot

解决方案


推荐阅读