1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 13:38:13 -05: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, SyncFolderCreate = 7,
SyncFolderUpdate = 8, SyncFolderUpdate = 8,
SyncCipherDelete = 9, SyncCipherDelete = 9,
SyncSettings = 10 SyncSettings = 10,
LogOut = 11,
} }
} }

View File

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

View File

@ -18,6 +18,7 @@ namespace Bit.Core.Services
Task PushSyncVaultAsync(Guid userId); Task PushSyncVaultAsync(Guid userId);
Task PushSyncOrgKeysAsync(Guid userId); Task PushSyncOrgKeysAsync(Guid userId);
Task PushSyncSettingsAsync(Guid userId); Task PushSyncSettingsAsync(Guid userId);
Task PushLogOutAsync(Guid userId);
Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier); Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier);
Task SendPayloadToOrganizationAsync(string orgId, 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) public async Task PushSyncCiphersAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncCiphers); await PushUserAsync(userId, PushType.SyncCiphers);
} }
public async Task PushSyncVaultAsync(Guid userId) public async Task PushSyncVaultAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncVault); await PushUserAsync(userId, PushType.SyncVault);
} }
public async Task PushSyncOrgKeysAsync(Guid userId) public async Task PushSyncOrgKeysAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncOrgKeys); await PushUserAsync(userId, PushType.SyncOrgKeys);
} }
public async Task PushSyncSettingsAsync(Guid userId) 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, UserId = userId,
Date = DateTime.UtcNow Date = DateTime.UtcNow

View File

@ -107,6 +107,12 @@ namespace Bit.Core.Services
return Task.FromResult(0); 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) public Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier)
{ {
PushToServices((s) => s.SendPayloadToUserAsync(userId, type, payload, 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) public async Task PushSyncCiphersAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncCiphers); await PushUserAsync(userId, PushType.SyncCiphers);
} }
public async Task PushSyncVaultAsync(Guid userId) public async Task PushSyncVaultAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncVault); await PushUserAsync(userId, PushType.SyncVault);
} }
public async Task PushSyncOrgKeysAsync(Guid userId) public async Task PushSyncOrgKeysAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncOrgKeys); await PushUserAsync(userId, PushType.SyncOrgKeys);
} }
public async Task PushSyncSettingsAsync(Guid userId) 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, UserId = userId,
Date = DateTime.UtcNow Date = DateTime.UtcNow

View File

@ -108,27 +108,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId) public async Task PushSyncCiphersAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncCiphers); await PushUserAsync(userId, PushType.SyncCiphers);
} }
public async Task PushSyncVaultAsync(Guid userId) public async Task PushSyncVaultAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncVault); await PushUserAsync(userId, PushType.SyncVault);
} }
public async Task PushSyncOrgKeysAsync(Guid userId) public async Task PushSyncOrgKeysAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncOrgKeys); await PushUserAsync(userId, PushType.SyncOrgKeys);
} }
public async Task PushSyncSettingsAsync(Guid userId) 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, UserId = userId,
Date = DateTime.UtcNow Date = DateTime.UtcNow

View File

@ -101,27 +101,32 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId) public async Task PushSyncCiphersAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncCiphers); await PushUserAsync(userId, PushType.SyncCiphers);
} }
public async Task PushSyncVaultAsync(Guid userId) public async Task PushSyncVaultAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncVault); await PushUserAsync(userId, PushType.SyncVault);
} }
public async Task PushSyncOrgKeysAsync(Guid userId) public async Task PushSyncOrgKeysAsync(Guid userId)
{ {
await PushSyncUserAsync(userId, PushType.SyncOrgKeys); await PushUserAsync(userId, PushType.SyncOrgKeys);
} }
public async Task PushSyncSettingsAsync(Guid userId) 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, UserId = userId,
Date = DateTime.UtcNow Date = DateTime.UtcNow

View File

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

View File

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