1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00

clear token by id

This commit is contained in:
Kyle Spearrin 2017-06-02 16:52:54 -04:00
parent bee1ac659b
commit 7b1c0d6df1
9 changed files with 54 additions and 23 deletions

View File

@ -108,7 +108,7 @@ namespace Bit.Api.Controllers
[HttpPost("identifier/{identifier}/clear-token")]
public async Task PutClearToken(string identifier)
{
var device = await _deviceRepository.GetByIdentifierAsync(identifier, _userService.GetProperUserId(User).Value);
var device = await _deviceRepository.GetByIdentifierAsync(identifier);
if(device == null)
{
throw new NotFoundException();

View File

@ -8,8 +8,9 @@ namespace Bit.Core.Repositories
public interface IDeviceRepository : IRepository<Device, Guid>
{
Task<Device> GetByIdAsync(Guid id, Guid userId);
Task<Device> GetByIdentifierAsync(string identifier);
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
Task ClearPushTokenByIdentifierAsync(string identifier);
Task ClearPushTokenAsync(Guid id);
}
}

View File

@ -30,6 +30,22 @@ namespace Bit.Core.Repositories.SqlServer
return device;
}
public async Task<Device> GetByIdentifierAsync(string identifier)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Device>(
$"[{Schema}].[{Table}_ReadByIdentifier]",
new
{
Identifier = identifier
},
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault();
}
}
public async Task<Device> GetByIdentifierAsync(string identifier, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
@ -60,13 +76,13 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task ClearPushTokenByIdentifierAsync(string identifier)
public async Task ClearPushTokenAsync(Guid id)
{
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
$"[{Schema}].[{Table}_ClearPushTokenByIdentifier]",
new { Identifier = identifier },
$"[{Schema}].[{Table}_ClearPushTokenById]",
new { Id = id },
commandType: CommandType.StoredProcedure);
}
}

View File

@ -35,7 +35,7 @@ namespace Bit.Core.Services
public async Task ClearTokenAsync(Device device)
{
await _deviceRepository.ClearPushTokenByIdentifierAsync(device.Identifier);
await _deviceRepository.ClearPushTokenAsync(device.Id);
await _pushRegistrationService.DeleteRegistrationAsync(device.Id);
}

View File

@ -50,9 +50,9 @@ namespace Bit.Core.Services
switch(device.Type)
{
case Enums.DeviceType.Android:
payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}";
messageTemplate = "{\"data\":{\"type\":\"#(type)\"}," +
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}";
payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}";
messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," +
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";
installation.Platform = NotificationPlatform.Gcm;
break;

View File

@ -149,7 +149,7 @@
<Build Include="dbo\Stored Procedures\User_ReadById.sql" />
<Build Include="dbo\Stored Procedures\User_Update.sql" />
<Build Include="dbo\Stored Procedures\User_UpdateKeys.sql" />
<Build Include="dbo\Stored Procedures\Device_ClearPushTokenByIdentifier.sql" />
<Build Include="dbo\Stored Procedures\Device_ClearPushTokenById.sql" />
<Build Include="dbo\Stored Procedures\Collection_CreateWithGroups.sql" />
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsById.sql" />
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroups.sql" />
@ -192,5 +192,6 @@
<Build Include="dbo\Stored Procedures\Organization_Create.sql" />
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
<Build Include="dbo\User Defined Types\SelectionReadOnlyArray.sql" />
<Build Include="dbo\Stored Procedures\Device_ReadByIdentifier.sql" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Device_ClearPushTokenById]
@Id NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Device]
SET
[PushToken] = NULL
WHERE
[Id] = @Id
END

View File

@ -1,13 +0,0 @@
CREATE PROCEDURE [dbo].[Device_ClearPushTokenByIdentifier]
@Identifier NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Device]
SET
[PushToken] = NULL
WHERE
[Identifier] = @Identifier
END

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Device_ReadByIdentifier]
@Identifier NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[DeviceView]
WHERE
[Identifier] = @Identifier
END