2022-06-29 19:46:41 -04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2016-06-18 16:03:33 -04:00
|
|
|
|
using Bit.Core.Enums;
|
2023-06-09 21:36:12 -04:00
|
|
|
|
using Bit.Core.Utilities;
|
2016-06-18 16:03:33 -04:00
|
|
|
|
|
2021-12-14 15:05:07 +00:00
|
|
|
|
namespace Bit.Api.Models.Request;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2017-01-24 22:46:54 -05:00
|
|
|
|
public class DeviceRequestModel
|
2016-06-18 16:03:33 -04:00
|
|
|
|
{
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
public DeviceType? Type { get; set; }
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[StringLength(50)]
|
|
|
|
|
|
public string Name { get; set; }
|
2016-06-21 00:08:22 -04:00
|
|
|
|
[Required]
|
|
|
|
|
|
[StringLength(50)]
|
|
|
|
|
|
public string Identifier { get; set; }
|
2016-06-18 16:03:33 -04:00
|
|
|
|
[StringLength(255)]
|
|
|
|
|
|
public string PushToken { get; set; }
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2016-06-18 16:03:33 -04:00
|
|
|
|
public Device ToDevice(Guid? userId = null)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2016-06-18 16:03:33 -04:00
|
|
|
|
return ToDevice(new Device
|
|
|
|
|
|
{
|
2017-01-24 22:46:54 -05:00
|
|
|
|
UserId = userId == null ? default(Guid) : userId.Value
|
2016-06-18 16:03:33 -04:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Device ToDevice(Device existingDevice)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingDevice.Name = Name;
|
2016-06-21 00:08:22 -04:00
|
|
|
|
existingDevice.Identifier = Identifier;
|
2016-06-18 16:03:33 -04:00
|
|
|
|
existingDevice.PushToken = PushToken;
|
|
|
|
|
|
existingDevice.Type = Type.Value;
|
|
|
|
|
|
|
|
|
|
|
|
return existingDevice;
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2016-06-21 00:08:22 -04:00
|
|
|
|
|
|
|
|
|
|
public class DeviceTokenRequestModel
|
|
|
|
|
|
{
|
|
|
|
|
|
[StringLength(255)]
|
|
|
|
|
|
public string PushToken { get; set; }
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2016-06-21 00:08:22 -04:00
|
|
|
|
public Device ToDevice(Device existingDevice)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2016-06-21 00:08:22 -04:00
|
|
|
|
existingDevice.PushToken = PushToken;
|
|
|
|
|
|
return existingDevice;
|
|
|
|
|
|
}
|
2016-06-18 16:03:33 -04:00
|
|
|
|
}
|
2023-06-09 21:36:12 -04:00
|
|
|
|
|
|
|
|
|
|
public class DeviceKeysRequestModel
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc cref="Device.EncryptedUserKey" />
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[EncryptedString]
|
|
|
|
|
|
public string EncryptedUserKey { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="Device.EncryptedPublicKey" />
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[EncryptedString]
|
|
|
|
|
|
public string EncryptedPublicKey { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="Device.EncryptedPrivateKey" />
|
|
|
|
|
|
[Required]
|
|
|
|
|
|
[EncryptedString]
|
|
|
|
|
|
public string EncryptedPrivateKey { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Device ToDevice(Device existingDevice)
|
|
|
|
|
|
{
|
|
|
|
|
|
existingDevice.EncryptedUserKey = EncryptedUserKey;
|
|
|
|
|
|
existingDevice.EncryptedPublicKey = EncryptedPublicKey;
|
|
|
|
|
|
existingDevice.EncryptedPrivateKey = EncryptedPrivateKey;
|
|
|
|
|
|
|
|
|
|
|
|
return existingDevice;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|