1
0
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:
Pierre HUBERT 2020-05-01 09:27:03 +02:00
parent 12f81f4d2c
commit 6d225354ce
3 changed files with 19 additions and 0 deletions

View File

@ -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
*

View File

@ -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

View File

@ -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
})