1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-17 02:01:53 +01:00

add logout notification

This commit is contained in:
Kyle Spearrin 2018-08-28 08:22:49 -04:00
parent 3e2b220074
commit 18713054f6
10 changed files with 62 additions and 27 deletions

View File

@ -13,6 +13,8 @@
SyncFolderCreate = 7,
SyncFolderUpdate = 8,
SyncCipherDelete = 9,
SyncSettings = 10
SyncSettings = 10,
LogOut = 11,
}
}

View File

@ -34,7 +34,7 @@ namespace Bit.Core.Models
public DateTime RevisionDate { get; set; }
}
public class SyncUserPushNotification
public class UserPushNotification
{
public Guid UserId { get; set; }
public DateTime Date { get; set; }

View File

@ -18,6 +18,7 @@ namespace Bit.Core.Services
Task PushSyncVaultAsync(Guid userId);
Task PushSyncOrgKeysAsync(Guid userId);
Task PushSyncSettingsAsync(Guid userId);
Task PushLogOutAsync(Guid userId);
Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier);
Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier);
}

View File

@ -104,27 +104,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncCiphers);
await PushUserAsync(userId, PushType.SyncCiphers);
}
public async Task PushSyncVaultAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncVault);
await PushUserAsync(userId, PushType.SyncVault);
}
public async Task PushSyncOrgKeysAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncOrgKeys);
await PushUserAsync(userId, PushType.SyncOrgKeys);
}
public async Task PushSyncSettingsAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncSettings);
await PushUserAsync(userId, PushType.SyncSettings);
}
private async Task PushSyncUserAsync(Guid userId, PushType type)
public async Task PushLogOutAsync(Guid userId)
{
var message = new SyncUserPushNotification
await PushUserAsync(userId, PushType.LogOut);
}
private async Task PushUserAsync(Guid userId, PushType type)
{
var message = new UserPushNotification
{
UserId = userId,
Date = DateTime.UtcNow

View File

@ -107,6 +107,12 @@ namespace Bit.Core.Services
return Task.FromResult(0);
}
public Task PushLogOutAsync(Guid userId)
{
PushToServices((s) => s.PushLogOutAsync(userId));
return Task.FromResult(0);
}
public Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier)
{
PushToServices((s) => s.SendPayloadToUserAsync(userId, type, payload, identifier));

View File

@ -95,27 +95,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncCiphers);
await PushUserAsync(userId, PushType.SyncCiphers);
}
public async Task PushSyncVaultAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncVault);
await PushUserAsync(userId, PushType.SyncVault);
}
public async Task PushSyncOrgKeysAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncOrgKeys);
await PushUserAsync(userId, PushType.SyncOrgKeys);
}
public async Task PushSyncSettingsAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncSettings);
await PushUserAsync(userId, PushType.SyncSettings);
}
private async Task PushSyncUserAsync(Guid userId, PushType type)
public async Task PushLogOutAsync(Guid userId)
{
var message = new SyncUserPushNotification
await PushUserAsync(userId, PushType.LogOut);
}
private async Task PushUserAsync(Guid userId, PushType type)
{
var message = new UserPushNotification
{
UserId = userId,
Date = DateTime.UtcNow

View File

@ -108,27 +108,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncCiphers);
await PushUserAsync(userId, PushType.SyncCiphers);
}
public async Task PushSyncVaultAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncVault);
await PushUserAsync(userId, PushType.SyncVault);
}
public async Task PushSyncOrgKeysAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncOrgKeys);
await PushUserAsync(userId, PushType.SyncOrgKeys);
}
public async Task PushSyncSettingsAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncSettings);
await PushUserAsync(userId, PushType.SyncSettings);
}
private async Task PushSyncUserAsync(Guid userId, PushType type)
public async Task PushLogOutAsync(Guid userId)
{
var message = new SyncUserPushNotification
await PushUserAsync(userId, PushType.LogOut);
}
private async Task PushUserAsync(Guid userId, PushType type)
{
var message = new UserPushNotification
{
UserId = userId,
Date = DateTime.UtcNow

View File

@ -101,27 +101,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncCiphers);
await PushUserAsync(userId, PushType.SyncCiphers);
}
public async Task PushSyncVaultAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncVault);
await PushUserAsync(userId, PushType.SyncVault);
}
public async Task PushSyncOrgKeysAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncOrgKeys);
await PushUserAsync(userId, PushType.SyncOrgKeys);
}
public async Task PushSyncSettingsAsync(Guid userId)
{
await PushSyncUserAsync(userId, PushType.SyncSettings);
await PushUserAsync(userId, PushType.SyncSettings);
}
private async Task PushSyncUserAsync(Guid userId, PushType type)
public async Task PushLogOutAsync(Guid userId)
{
var message = new SyncUserPushNotification
await PushUserAsync(userId, PushType.LogOut);
}
private async Task PushUserAsync(Guid userId, PushType type)
{
var message = new UserPushNotification
{
UserId = userId,
Date = DateTime.UtcNow

View File

@ -58,6 +58,11 @@ namespace Bit.Core.Services
return Task.FromResult(0);
}
public Task PushLogOutAsync(Guid userId)
{
return Task.FromResult(0);
}
public Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier)
{
return Task.FromResult(0);

View File

@ -47,8 +47,9 @@ namespace Bit.Notifications
case PushType.SyncVault:
case PushType.SyncOrgKeys:
case PushType.SyncSettings:
case PushType.LogOut:
var userNotification =
JsonConvert.DeserializeObject<PushNotificationData<SyncUserPushNotification>>(
JsonConvert.DeserializeObject<PushNotificationData<UserPushNotification>>(
notificationJson);
await hubContext.Clients.User(userNotification.Payload.UserId.ToString())
.SendAsync("ReceiveMessage", userNotification, cancellationToken);