mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-21 21:09:22 +00:00
Can disconnect user from all its devices
This commit is contained in:
parent
12f81f4d2c
commit
6d225354ce
@ -102,6 +102,18 @@ export class AccountController {
|
||||
handler.success("User has been disconnected!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect current user from all its connected devices
|
||||
* (destroy all its login tokens)
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async DisconnectAllDevices(h: RequestHandler) {
|
||||
await AccountHelper.DeleteAllUserLoginTokens(h.getUserId());
|
||||
|
||||
h.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user ID
|
||||
*
|
||||
|
@ -66,6 +66,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/account/logout", cb: (h) => AccountController.LogoutUser(h)},
|
||||
{path: "/user/disconnectUSER", cb: (h) => AccountController.LogoutUser(h)}, // Legacy
|
||||
|
||||
{path: "/account/disconnect_all_devices", cb: (h) => AccountController.DisconnectAllDevices(h)},
|
||||
|
||||
{path: "/account/id", cb: (h) => AccountController.CurrentUserID(h)},
|
||||
{path: "/user/getCurrentUserID", cb: (h) => AccountController.CurrentUserID(h)}, // Legacy
|
||||
|
@ -317,6 +317,11 @@ export class AccountHelper {
|
||||
* @param userID Target user ID
|
||||
*/
|
||||
public static async DeleteAllUserLoginTokens(userID: number) {
|
||||
|
||||
// First, close all sockets of user
|
||||
await UserWebSocketController.CloseAllUserSockets(userID);
|
||||
|
||||
// Destroy tokens in the database
|
||||
await DatabaseHelper.DeleteRows(USERS_TOKENS_TABLE, {
|
||||
user_id: userID
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user