mirror of
https://github.com/bitwarden/server.git
synced 2025-04-18 19:48:12 -05:00
clear token by id
This commit is contained in:
parent
bee1ac659b
commit
7b1c0d6df1
@ -108,7 +108,7 @@ namespace Bit.Api.Controllers
|
|||||||
[HttpPost("identifier/{identifier}/clear-token")]
|
[HttpPost("identifier/{identifier}/clear-token")]
|
||||||
public async Task PutClearToken(string identifier)
|
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)
|
if(device == null)
|
||||||
{
|
{
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
|
@ -8,8 +8,9 @@ namespace Bit.Core.Repositories
|
|||||||
public interface IDeviceRepository : IRepository<Device, Guid>
|
public interface IDeviceRepository : IRepository<Device, Guid>
|
||||||
{
|
{
|
||||||
Task<Device> GetByIdAsync(Guid id, Guid userId);
|
Task<Device> GetByIdAsync(Guid id, Guid userId);
|
||||||
|
Task<Device> GetByIdentifierAsync(string identifier);
|
||||||
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
|
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
|
||||||
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
|
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
|
||||||
Task ClearPushTokenByIdentifierAsync(string identifier);
|
Task ClearPushTokenAsync(Guid id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,22 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
return device;
|
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)
|
public async Task<Device> GetByIdentifierAsync(string identifier, Guid userId)
|
||||||
{
|
{
|
||||||
using(var connection = new SqlConnection(ConnectionString))
|
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))
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
await connection.ExecuteAsync(
|
await connection.ExecuteAsync(
|
||||||
$"[{Schema}].[{Table}_ClearPushTokenByIdentifier]",
|
$"[{Schema}].[{Table}_ClearPushTokenById]",
|
||||||
new { Identifier = identifier },
|
new { Id = id },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public async Task ClearTokenAsync(Device device)
|
public async Task ClearTokenAsync(Device device)
|
||||||
{
|
{
|
||||||
await _deviceRepository.ClearPushTokenByIdentifierAsync(device.Identifier);
|
await _deviceRepository.ClearPushTokenAsync(device.Id);
|
||||||
await _pushRegistrationService.DeleteRegistrationAsync(device.Id);
|
await _pushRegistrationService.DeleteRegistrationAsync(device.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +50,9 @@ namespace Bit.Core.Services
|
|||||||
switch(device.Type)
|
switch(device.Type)
|
||||||
{
|
{
|
||||||
case Enums.DeviceType.Android:
|
case Enums.DeviceType.Android:
|
||||||
payloadTemplate = "{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}";
|
payloadTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\",\"payload\":\"$(payload)\"}}}";
|
||||||
messageTemplate = "{\"data\":{\"type\":\"#(type)\"}," +
|
messageTemplate = "{\"data\":{\"data\":{\"type\":\"#(type)\"}," +
|
||||||
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}";
|
"\"notification\":{\"title\":\"$(title)\",\"body\":\"$(message)\"}}}";
|
||||||
|
|
||||||
installation.Platform = NotificationPlatform.Gcm;
|
installation.Platform = NotificationPlatform.Gcm;
|
||||||
break;
|
break;
|
||||||
|
@ -149,7 +149,7 @@
|
|||||||
<Build Include="dbo\Stored Procedures\User_ReadById.sql" />
|
<Build Include="dbo\Stored Procedures\User_ReadById.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\User_Update.sql" />
|
<Build Include="dbo\Stored Procedures\User_Update.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\User_UpdateKeys.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_CreateWithGroups.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsById.sql" />
|
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsById.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroups.sql" />
|
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroups.sql" />
|
||||||
@ -192,5 +192,6 @@
|
|||||||
<Build Include="dbo\Stored Procedures\Organization_Create.sql" />
|
<Build Include="dbo\Stored Procedures\Organization_Create.sql" />
|
||||||
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
|
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
|
||||||
<Build Include="dbo\User Defined Types\SelectionReadOnlyArray.sql" />
|
<Build Include="dbo\User Defined Types\SelectionReadOnlyArray.sql" />
|
||||||
|
<Build Include="dbo\Stored Procedures\Device_ReadByIdentifier.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
13
src/Sql/dbo/Stored Procedures/Device_ClearPushTokenById.sql
Normal file
13
src/Sql/dbo/Stored Procedures/Device_ClearPushTokenById.sql
Normal 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
|
@ -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
|
|
13
src/Sql/dbo/Stored Procedures/Device_ReadByIdentifier.sql
Normal file
13
src/Sql/dbo/Stored Procedures/Device_ReadByIdentifier.sql
Normal 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
|
Loading…
x
Reference in New Issue
Block a user