2
0

User.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.ComponentModel.DataAnnotations.Schema;
  6. using System.Linq;
  7. using System.Text.Json.Serialization;
  8. using Jellyfin.Data.Enums;
  9. using Jellyfin.Data.Interfaces;
  10. namespace Jellyfin.Data.Entities
  11. {
  12. /// <summary>
  13. /// An entity representing a user.
  14. /// </summary>
  15. public class User : IHasPermissions, IHasConcurrencyToken
  16. {
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="User"/> class.
  19. /// Public constructor with required data.
  20. /// </summary>
  21. /// <param name="username">The username for the new user.</param>
  22. /// <param name="authenticationProviderId">The Id of the user's authentication provider.</param>
  23. /// <param name="passwordResetProviderId">The Id of the user's password reset provider.</param>
  24. public User(string username, string authenticationProviderId, string passwordResetProviderId)
  25. {
  26. ArgumentException.ThrowIfNullOrEmpty(username);
  27. ArgumentException.ThrowIfNullOrEmpty(authenticationProviderId);
  28. ArgumentException.ThrowIfNullOrEmpty(passwordResetProviderId);
  29. Username = username;
  30. AuthenticationProviderId = authenticationProviderId;
  31. PasswordResetProviderId = passwordResetProviderId;
  32. AccessSchedules = new HashSet<AccessSchedule>();
  33. DisplayPreferences = new HashSet<DisplayPreferences>();
  34. ItemDisplayPreferences = new HashSet<ItemDisplayPreferences>();
  35. // Groups = new HashSet<Group>();
  36. Permissions = new HashSet<Permission>();
  37. Preferences = new HashSet<Preference>();
  38. // ProviderMappings = new HashSet<ProviderMapping>();
  39. // Set default values
  40. Id = Guid.NewGuid();
  41. InvalidLoginAttemptCount = 0;
  42. EnableUserPreferenceAccess = true;
  43. MustUpdatePassword = false;
  44. DisplayMissingEpisodes = false;
  45. DisplayCollectionsView = false;
  46. HidePlayedInLatest = true;
  47. RememberAudioSelections = true;
  48. RememberSubtitleSelections = true;
  49. EnableNextEpisodeAutoPlay = true;
  50. EnableAutoLogin = false;
  51. PlayDefaultAudioTrack = true;
  52. SubtitleMode = SubtitlePlaybackMode.Default;
  53. SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups;
  54. }
  55. /// <summary>
  56. /// Gets or sets the Id of the user.
  57. /// </summary>
  58. /// <remarks>
  59. /// Identity, Indexed, Required.
  60. /// </remarks>
  61. [JsonIgnore]
  62. public Guid Id { get; set; }
  63. /// <summary>
  64. /// Gets or sets the user's name.
  65. /// </summary>
  66. /// <remarks>
  67. /// Required, Max length = 255.
  68. /// </remarks>
  69. [MaxLength(255)]
  70. [StringLength(255)]
  71. public string Username { get; set; }
  72. /// <summary>
  73. /// Gets or sets the user's password, or <c>null</c> if none is set.
  74. /// </summary>
  75. /// <remarks>
  76. /// Max length = 65535.
  77. /// </remarks>
  78. [MaxLength(65535)]
  79. [StringLength(65535)]
  80. public string? Password { get; set; }
  81. /// <summary>
  82. /// Gets or sets a value indicating whether the user must update their password.
  83. /// </summary>
  84. /// <remarks>
  85. /// Required.
  86. /// </remarks>
  87. public bool MustUpdatePassword { get; set; }
  88. /// <summary>
  89. /// Gets or sets the audio language preference.
  90. /// </summary>
  91. /// <remarks>
  92. /// Max length = 255.
  93. /// </remarks>
  94. [MaxLength(255)]
  95. [StringLength(255)]
  96. public string? AudioLanguagePreference { get; set; }
  97. /// <summary>
  98. /// Gets or sets the authentication provider id.
  99. /// </summary>
  100. /// <remarks>
  101. /// Required, Max length = 255.
  102. /// </remarks>
  103. [MaxLength(255)]
  104. [StringLength(255)]
  105. public string AuthenticationProviderId { get; set; }
  106. /// <summary>
  107. /// Gets or sets the password reset provider id.
  108. /// </summary>
  109. /// <remarks>
  110. /// Required, Max length = 255.
  111. /// </remarks>
  112. [MaxLength(255)]
  113. [StringLength(255)]
  114. public string PasswordResetProviderId { get; set; }
  115. /// <summary>
  116. /// Gets or sets the invalid login attempt count.
  117. /// </summary>
  118. /// <remarks>
  119. /// Required.
  120. /// </remarks>
  121. public int InvalidLoginAttemptCount { get; set; }
  122. /// <summary>
  123. /// Gets or sets the last activity date.
  124. /// </summary>
  125. public DateTime? LastActivityDate { get; set; }
  126. /// <summary>
  127. /// Gets or sets the last login date.
  128. /// </summary>
  129. public DateTime? LastLoginDate { get; set; }
  130. /// <summary>
  131. /// Gets or sets the number of login attempts the user can make before they are locked out.
  132. /// </summary>
  133. public int? LoginAttemptsBeforeLockout { get; set; }
  134. /// <summary>
  135. /// Gets or sets the maximum number of active sessions the user can have at once.
  136. /// </summary>
  137. public int MaxActiveSessions { get; set; }
  138. /// <summary>
  139. /// Gets or sets the subtitle mode.
  140. /// </summary>
  141. /// <remarks>
  142. /// Required.
  143. /// </remarks>
  144. public SubtitlePlaybackMode SubtitleMode { get; set; }
  145. /// <summary>
  146. /// Gets or sets a value indicating whether the default audio track should be played.
  147. /// </summary>
  148. /// <remarks>
  149. /// Required.
  150. /// </remarks>
  151. public bool PlayDefaultAudioTrack { get; set; }
  152. /// <summary>
  153. /// Gets or sets the subtitle language preference.
  154. /// </summary>
  155. /// <remarks>
  156. /// Max length = 255.
  157. /// </remarks>
  158. [MaxLength(255)]
  159. [StringLength(255)]
  160. public string? SubtitleLanguagePreference { get; set; }
  161. /// <summary>
  162. /// Gets or sets a value indicating whether missing episodes should be displayed.
  163. /// </summary>
  164. /// <remarks>
  165. /// Required.
  166. /// </remarks>
  167. public bool DisplayMissingEpisodes { get; set; }
  168. /// <summary>
  169. /// Gets or sets a value indicating whether to display the collections view.
  170. /// </summary>
  171. /// <remarks>
  172. /// Required.
  173. /// </remarks>
  174. public bool DisplayCollectionsView { get; set; }
  175. /// <summary>
  176. /// Gets or sets a value indicating whether the user has a local password.
  177. /// </summary>
  178. /// <remarks>
  179. /// Required.
  180. /// </remarks>
  181. public bool EnableLocalPassword { get; set; }
  182. /// <summary>
  183. /// Gets or sets a value indicating whether the server should hide played content in "Latest".
  184. /// </summary>
  185. /// <remarks>
  186. /// Required.
  187. /// </remarks>
  188. public bool HidePlayedInLatest { get; set; }
  189. /// <summary>
  190. /// Gets or sets a value indicating whether to remember audio selections on played content.
  191. /// </summary>
  192. /// <remarks>
  193. /// Required.
  194. /// </remarks>
  195. public bool RememberAudioSelections { get; set; }
  196. /// <summary>
  197. /// Gets or sets a value indicating whether to remember subtitle selections on played content.
  198. /// </summary>
  199. /// <remarks>
  200. /// Required.
  201. /// </remarks>
  202. public bool RememberSubtitleSelections { get; set; }
  203. /// <summary>
  204. /// Gets or sets a value indicating whether to enable auto-play for the next episode.
  205. /// </summary>
  206. /// <remarks>
  207. /// Required.
  208. /// </remarks>
  209. public bool EnableNextEpisodeAutoPlay { get; set; }
  210. /// <summary>
  211. /// Gets or sets a value indicating whether the user should auto-login.
  212. /// </summary>
  213. /// <remarks>
  214. /// Required.
  215. /// </remarks>
  216. public bool EnableAutoLogin { get; set; }
  217. /// <summary>
  218. /// Gets or sets a value indicating whether the user can change their preferences.
  219. /// </summary>
  220. /// <remarks>
  221. /// Required.
  222. /// </remarks>
  223. public bool EnableUserPreferenceAccess { get; set; }
  224. /// <summary>
  225. /// Gets or sets the maximum parental age rating.
  226. /// </summary>
  227. public int? MaxParentalAgeRating { get; set; }
  228. /// <summary>
  229. /// Gets or sets the remote client bitrate limit.
  230. /// </summary>
  231. public int? RemoteClientBitrateLimit { get; set; }
  232. /// <summary>
  233. /// Gets or sets the internal id.
  234. /// This is a temporary stopgap for until the library db is migrated.
  235. /// This corresponds to the value of the index of this user in the library db.
  236. /// </summary>
  237. public long InternalId { get; set; }
  238. /// <summary>
  239. /// Gets or sets the user's profile image. Can be <c>null</c>.
  240. /// </summary>
  241. // [ForeignKey("UserId")]
  242. public virtual ImageInfo? ProfileImage { get; set; }
  243. /// <summary>
  244. /// Gets the user's display preferences.
  245. /// </summary>
  246. public virtual ICollection<DisplayPreferences> DisplayPreferences { get; private set; }
  247. /// <summary>
  248. /// Gets or sets the level of sync play permissions this user has.
  249. /// </summary>
  250. public SyncPlayUserAccessType SyncPlayAccess { get; set; }
  251. /// <summary>
  252. /// Gets or sets the cast receiver id.
  253. /// </summary>
  254. [StringLength(32)]
  255. public string? CastReceiverId { get; set; }
  256. /// <inheritdoc />
  257. [ConcurrencyCheck]
  258. public uint RowVersion { get; private set; }
  259. /// <summary>
  260. /// Gets the list of access schedules this user has.
  261. /// </summary>
  262. public virtual ICollection<AccessSchedule> AccessSchedules { get; private set; }
  263. /// <summary>
  264. /// Gets the list of item display preferences.
  265. /// </summary>
  266. public virtual ICollection<ItemDisplayPreferences> ItemDisplayPreferences { get; private set; }
  267. /*
  268. /// <summary>
  269. /// Gets the list of groups this user is a member of.
  270. /// </summary>
  271. public virtual ICollection<Group> Groups { get; private set; }
  272. */
  273. /// <summary>
  274. /// Gets the list of permissions this user has.
  275. /// </summary>
  276. [ForeignKey("Permission_Permissions_Guid")]
  277. public virtual ICollection<Permission> Permissions { get; private set; }
  278. /*
  279. /// <summary>
  280. /// Gets the list of provider mappings this user has.
  281. /// </summary>
  282. public virtual ICollection<ProviderMapping> ProviderMappings { get; private set; }
  283. */
  284. /// <summary>
  285. /// Gets the list of preferences this user has.
  286. /// </summary>
  287. [ForeignKey("Preference_Preferences_Guid")]
  288. public virtual ICollection<Preference> Preferences { get; private set; }
  289. /// <inheritdoc/>
  290. public void OnSavingChanges()
  291. {
  292. RowVersion++;
  293. }
  294. }
  295. }