Device.cs 3.1 KB

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