| | 1 | | using System; |
| | 2 | | using System.ComponentModel.DataAnnotations; |
| | 3 | | using System.ComponentModel.DataAnnotations.Schema; |
| | 4 | | using System.Globalization; |
| | 5 | |
|
| | 6 | | namespace Jellyfin.Database.Implementations.Entities.Security |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// An entity representing a device. |
| | 10 | | /// </summary> |
| | 11 | | public class Device |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Initializes a new instance of the <see cref="Device"/> class. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="userId">The user id.</param> |
| | 17 | | /// <param name="appName">The app name.</param> |
| | 18 | | /// <param name="appVersion">The app version.</param> |
| | 19 | | /// <param name="deviceName">The device name.</param> |
| | 20 | | /// <param name="deviceId">The device id.</param> |
| | 21 | | public Device(Guid userId, string appName, string appVersion, string deviceName, string deviceId) |
| | 22 | | { |
| 15 | 23 | | UserId = userId; |
| 15 | 24 | | AppName = appName; |
| 15 | 25 | | AppVersion = appVersion; |
| 15 | 26 | | DeviceName = deviceName; |
| 15 | 27 | | DeviceId = deviceId; |
| | 28 | |
|
| 15 | 29 | | AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); |
| 15 | 30 | | DateCreated = DateTime.UtcNow; |
| 15 | 31 | | DateModified = DateCreated; |
| 15 | 32 | | DateLastActivity = DateCreated; |
| | 33 | |
|
| | 34 | | // Non-nullable for EF Core, as this is a required relationship. |
| 15 | 35 | | User = null!; |
| 15 | 36 | | } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets the id. |
| | 40 | | /// </summary> |
| | 41 | | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] |
| | 42 | | public int Id { get; private set; } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets the user id. |
| | 46 | | /// </summary> |
| | 47 | | public Guid UserId { get; private set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets or sets the access token. |
| | 51 | | /// </summary> |
| | 52 | | public string AccessToken { get; set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets or sets the app name. |
| | 56 | | /// </summary> |
| | 57 | | [MaxLength(64)] |
| | 58 | | [StringLength(64)] |
| | 59 | | public string AppName { get; set; } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Gets or sets the app version. |
| | 63 | | /// </summary> |
| | 64 | | [MaxLength(32)] |
| | 65 | | [StringLength(32)] |
| | 66 | | public string AppVersion { get; set; } |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// Gets or sets the device name. |
| | 70 | | /// </summary> |
| | 71 | | [MaxLength(64)] |
| | 72 | | [StringLength(64)] |
| | 73 | | public string DeviceName { get; set; } |
| | 74 | |
|
| | 75 | | /// <summary> |
| | 76 | | /// Gets or sets the device id. |
| | 77 | | /// </summary> |
| | 78 | | [MaxLength(256)] |
| | 79 | | [StringLength(256)] |
| | 80 | | public string DeviceId { get; set; } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// Gets or sets a value indicating whether this device is active. |
| | 84 | | /// </summary> |
| | 85 | | public bool IsActive { get; set; } |
| | 86 | |
|
| | 87 | | /// <summary> |
| | 88 | | /// Gets or sets the date created. |
| | 89 | | /// </summary> |
| | 90 | | public DateTime DateCreated { get; set; } |
| | 91 | |
|
| | 92 | | /// <summary> |
| | 93 | | /// Gets or sets the date modified. |
| | 94 | | /// </summary> |
| | 95 | | public DateTime DateModified { get; set; } |
| | 96 | |
|
| | 97 | | /// <summary> |
| | 98 | | /// Gets or sets the date of last activity. |
| | 99 | | /// </summary> |
| | 100 | | public DateTime DateLastActivity { get; set; } |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// Gets the user. |
| | 104 | | /// </summary> |
| | 105 | | public User User { get; private set; } |
| | 106 | | } |
| | 107 | | } |