1
0
mirror of https://github.com/bitwarden/server synced 2025-12-24 12:13:17 +00:00
Files
server/src/Api/Models/Request/DeviceRequestModels.cs
Justin Baur 5874ff42c3 [PM-1380] Modify Device Table (#2937)
* Update Models

- Add Controller Method

* Add MSSQL Migration

* Update SQL Proj

* Update SQL Migration

* Update Models

* Update SQL Project

* Add EF Migrations

* Switch to using Identifier

* Update Code Comment
2023-06-09 21:36:12 -04:00

78 lines
1.9 KiB
C#

using System.ComponentModel.DataAnnotations;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Request;
public class DeviceRequestModel
{
[Required]
public DeviceType? Type { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
[Required]
[StringLength(50)]
public string Identifier { get; set; }
[StringLength(255)]
public string PushToken { get; set; }
public Device ToDevice(Guid? userId = null)
{
return ToDevice(new Device
{
UserId = userId == null ? default(Guid) : userId.Value
});
}
public Device ToDevice(Device existingDevice)
{
existingDevice.Name = Name;
existingDevice.Identifier = Identifier;
existingDevice.PushToken = PushToken;
existingDevice.Type = Type.Value;
return existingDevice;
}
}
public class DeviceTokenRequestModel
{
[StringLength(255)]
public string PushToken { get; set; }
public Device ToDevice(Device existingDevice)
{
existingDevice.PushToken = PushToken;
return existingDevice;
}
}
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;
}
}