From 0e6fd218058f18e4239367aeaf5a01e2799aa384 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 21 Jun 2016 22:17:31 -0400 Subject: [PATCH] Updates for devices --- src/Api/Models/Request/DeviceRequestModels.cs | 2 +- src/Core/Identity/JwtBearerSignInManager.cs | 1 + src/Sql/dbo/Stored Procedures/Device_Create.sql | 3 +++ src/Sql/dbo/Stored Procedures/Device_Update.sql | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Api/Models/Request/DeviceRequestModels.cs b/src/Api/Models/Request/DeviceRequestModels.cs index a836e110c..15602f458 100644 --- a/src/Api/Models/Request/DeviceRequestModels.cs +++ b/src/Api/Models/Request/DeviceRequestModels.cs @@ -23,7 +23,7 @@ namespace Bit.Api.Models { return ToDevice(new Device { - UserId = new Guid(userId) + UserId = userId == null ? default(Guid) : new Guid(userId) }); } diff --git a/src/Core/Identity/JwtBearerSignInManager.cs b/src/Core/Identity/JwtBearerSignInManager.cs index dc12dc66c..67140a8a1 100644 --- a/src/Core/Identity/JwtBearerSignInManager.cs +++ b/src/Core/Identity/JwtBearerSignInManager.cs @@ -74,6 +74,7 @@ namespace Bit.Core.Identity var existingDevice = await _deviceRepository.GetByIdentifierAsync(device.Identifier, user.Id); if(existingDevice == null) { + device.UserId = user.Id; await _deviceRepository.CreateAsync(device); } } diff --git a/src/Sql/dbo/Stored Procedures/Device_Create.sql b/src/Sql/dbo/Stored Procedures/Device_Create.sql index 9424ed30a..25ee051d4 100644 --- a/src/Sql/dbo/Stored Procedures/Device_Create.sql +++ b/src/Sql/dbo/Stored Procedures/Device_Create.sql @@ -3,6 +3,7 @@ @UserId UNIQUEIDENTIFIER, @Name NVARCHAR(50), @Type TINYINT, + @Identifier NVARCHAR(50), @PushToken NVARCHAR(255), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) @@ -16,6 +17,7 @@ BEGIN [UserId], [Name], [Type], + [Identifier], [PushToken], [CreationDate], [RevisionDate] @@ -26,6 +28,7 @@ BEGIN @UserId, @Name, @Type, + @Identifier, @PushToken, @CreationDate, @RevisionDate diff --git a/src/Sql/dbo/Stored Procedures/Device_Update.sql b/src/Sql/dbo/Stored Procedures/Device_Update.sql index f1f4682f1..a024fc3ec 100644 --- a/src/Sql/dbo/Stored Procedures/Device_Update.sql +++ b/src/Sql/dbo/Stored Procedures/Device_Update.sql @@ -3,6 +3,7 @@ @UserId UNIQUEIDENTIFIER, @Name NVARCHAR(50), @Type TINYINT, + @Identifier NVARCHAR(50), @PushToken NVARCHAR(255), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) @@ -16,6 +17,7 @@ BEGIN [UserId] = @UserId, [Name] = @Name, [Type] = @Type, + [Identifier] = @Identifier, [PushToken] = @PushToken, [CreationDate] = @CreationDate, [RevisionDate] = @RevisionDate