1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-20 11:04:31 -05:00

Fixed null reference to device when loggin in for website

This commit is contained in:
Kyle Spearrin 2016-07-23 17:12:42 -04:00
parent d300c82ffd
commit 4a8162d09a
2 changed files with 19 additions and 15 deletions

View File

@ -111,11 +111,14 @@ namespace Bit.Core.Identity
success.Token = token; success.Token = token;
success.User = user; success.User = user;
var existingDevice = await _deviceRepository.GetByIdentifierAsync(device.Identifier, user.Id); if(device != null)
if(existingDevice == null)
{ {
device.UserId = user.Id; var existingDevice = await _deviceRepository.GetByIdentifierAsync(device.Identifier, user.Id);
await _deviceRepository.CreateAsync(device); if(existingDevice == null)
{
device.UserId = user.Id;
await _deviceRepository.CreateAsync(device);
}
} }
return success; return success;

View File

@ -14,6 +14,7 @@ using Bit.Core.Enums;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace Bit.Core.Services namespace Bit.Core.Services
{ {
@ -104,7 +105,7 @@ namespace Bit.Core.Services
_gcmBroker.OnNotificationFailed += GcmBroker_OnNotificationFailed; _gcmBroker.OnNotificationFailed += GcmBroker_OnNotificationFailed;
_gcmBroker.OnNotificationSucceeded += (notification) => _gcmBroker.OnNotificationSucceeded += (notification) =>
{ {
Console.WriteLine("GCM Notification Sent!"); Debug.WriteLine("GCM Notification Sent!");
}; };
_gcmBroker.Start(); _gcmBroker.Start();
} }
@ -122,7 +123,7 @@ namespace Bit.Core.Services
var gcmNotification = notificationException.Notification; var gcmNotification = notificationException.Notification;
var description = notificationException.Description; var description = notificationException.Description;
Console.WriteLine($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}"); Debug.WriteLine($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
} }
else if(ex is GcmMulticastResultException) else if(ex is GcmMulticastResultException)
{ {
@ -130,7 +131,7 @@ namespace Bit.Core.Services
foreach(var succeededNotification in multicastException.Succeeded) foreach(var succeededNotification in multicastException.Succeeded)
{ {
Console.WriteLine($"GCM Notification Failed: ID={succeededNotification.MessageId}"); Debug.WriteLine($"GCM Notification Failed: ID={succeededNotification.MessageId}");
} }
foreach(var failedKvp in multicastException.Failed) foreach(var failedKvp in multicastException.Failed)
@ -138,7 +139,7 @@ namespace Bit.Core.Services
var n = failedKvp.Key; var n = failedKvp.Key;
var e = failedKvp.Value; var e = failedKvp.Value;
Console.WriteLine($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Message}"); Debug.WriteLine($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Message}");
} }
} }
@ -149,23 +150,23 @@ namespace Bit.Core.Services
var oldId = expiredException.OldSubscriptionId; var oldId = expiredException.OldSubscriptionId;
var newId = expiredException.NewSubscriptionId; var newId = expiredException.NewSubscriptionId;
Console.WriteLine($"Device RegistrationId Expired: {oldId}"); Debug.WriteLine($"Device RegistrationId Expired: {oldId}");
if(!string.IsNullOrWhiteSpace(newId)) if(!string.IsNullOrWhiteSpace(newId))
{ {
// If this value isn't null, our subscription changed and we should update our database // If this value isn't null, our subscription changed and we should update our database
Console.WriteLine($"Device RegistrationId Changed To: {newId}"); Debug.WriteLine($"Device RegistrationId Changed To: {newId}");
} }
} }
else if(ex is RetryAfterException) else if(ex is RetryAfterException)
{ {
var retryException = (RetryAfterException)ex; var retryException = (RetryAfterException)ex;
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date // If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
Console.WriteLine($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}"); Debug.WriteLine($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
} }
else else
{ {
Console.WriteLine("GCM Notification Failed for some unknown reason"); Debug.WriteLine("GCM Notification Failed for some unknown reason");
} }
// Mark it as handled // Mark it as handled
@ -195,7 +196,7 @@ namespace Bit.Core.Services
_apnsBroker.OnNotificationFailed += ApnsBroker_OnNotificationFailed; _apnsBroker.OnNotificationFailed += ApnsBroker_OnNotificationFailed;
_apnsBroker.OnNotificationSucceeded += (notification) => _apnsBroker.OnNotificationSucceeded += (notification) =>
{ {
Console.WriteLine("Apple Notification Sent!"); Debug.WriteLine("Apple Notification Sent!");
}; };
_apnsBroker.Start(); _apnsBroker.Start();
@ -217,12 +218,12 @@ namespace Bit.Core.Services
var apnsNotification = notificationException.Notification; var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode; var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}"); Debug.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
} }
else else
{ {
// Inner exception might hold more useful information like an ApnsConnectionException // Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}"); Debug.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
} }
// Mark it as handled // Mark it as handled