using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text.Json.Serialization; using Jellyfin.Data.Enums; using Jellyfin.Data.Interfaces; namespace Jellyfin.Data.Entities { /// /// An entity representing a user. /// public class User : IHasPermissions, IHasConcurrencyToken { /// /// Initializes a new instance of the class. /// Public constructor with required data. /// /// The username for the new user. /// The Id of the user's authentication provider. /// The Id of the user's password reset provider. public User(string username, string authenticationProviderId, string passwordResetProviderId) { ArgumentException.ThrowIfNullOrEmpty(username); ArgumentException.ThrowIfNullOrEmpty(authenticationProviderId); ArgumentException.ThrowIfNullOrEmpty(passwordResetProviderId); Username = username; AuthenticationProviderId = authenticationProviderId; PasswordResetProviderId = passwordResetProviderId; AccessSchedules = new HashSet(); DisplayPreferences = new HashSet(); ItemDisplayPreferences = new HashSet(); // Groups = new HashSet(); Permissions = new HashSet(); Preferences = new HashSet(); // ProviderMappings = new HashSet(); // Set default values Id = Guid.NewGuid(); InvalidLoginAttemptCount = 0; EnableUserPreferenceAccess = true; MustUpdatePassword = false; DisplayMissingEpisodes = false; DisplayCollectionsView = false; HidePlayedInLatest = true; RememberAudioSelections = true; RememberSubtitleSelections = true; EnableNextEpisodeAutoPlay = true; EnableAutoLogin = false; PlayDefaultAudioTrack = true; SubtitleMode = SubtitlePlaybackMode.Default; SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups; } /// /// Gets or sets the Id of the user. /// /// /// Identity, Indexed, Required. /// [JsonIgnore] public Guid Id { get; set; } /// /// Gets or sets the user's name. /// /// /// Required, Max length = 255. /// [MaxLength(255)] [StringLength(255)] public string Username { get; set; } /// /// Gets or sets the user's password, or null if none is set. /// /// /// Max length = 65535. /// [MaxLength(65535)] [StringLength(65535)] public string? Password { get; set; } /// /// Gets or sets a value indicating whether the user must update their password. /// /// /// Required. /// public bool MustUpdatePassword { get; set; } /// /// Gets or sets the audio language preference. /// /// /// Max length = 255. /// [MaxLength(255)] [StringLength(255)] public string? AudioLanguagePreference { get; set; } /// /// Gets or sets the authentication provider id. /// /// /// Required, Max length = 255. /// [MaxLength(255)] [StringLength(255)] public string AuthenticationProviderId { get; set; } /// /// Gets or sets the password reset provider id. /// /// /// Required, Max length = 255. /// [MaxLength(255)] [StringLength(255)] public string PasswordResetProviderId { get; set; } /// /// Gets or sets the invalid login attempt count. /// /// /// Required. /// public int InvalidLoginAttemptCount { get; set; } /// /// Gets or sets the last activity date. /// public DateTime? LastActivityDate { get; set; } /// /// Gets or sets the last login date. /// public DateTime? LastLoginDate { get; set; } /// /// Gets or sets the number of login attempts the user can make before they are locked out. /// public int? LoginAttemptsBeforeLockout { get; set; } /// /// Gets or sets the maximum number of active sessions the user can have at once. /// public int MaxActiveSessions { get; set; } /// /// Gets or sets the subtitle mode. /// /// /// Required. /// public SubtitlePlaybackMode SubtitleMode { get; set; } /// /// Gets or sets a value indicating whether the default audio track should be played. /// /// /// Required. /// public bool PlayDefaultAudioTrack { get; set; } /// /// Gets or sets the subtitle language preference. /// /// /// Max length = 255. /// [MaxLength(255)] [StringLength(255)] public string? SubtitleLanguagePreference { get; set; } /// /// Gets or sets a value indicating whether missing episodes should be displayed. /// /// /// Required. /// public bool DisplayMissingEpisodes { get; set; } /// /// Gets or sets a value indicating whether to display the collections view. /// /// /// Required. /// public bool DisplayCollectionsView { get; set; } /// /// Gets or sets a value indicating whether the user has a local password. /// /// /// Required. /// public bool EnableLocalPassword { get; set; } /// /// Gets or sets a value indicating whether the server should hide played content in "Latest". /// /// /// Required. /// public bool HidePlayedInLatest { get; set; } /// /// Gets or sets a value indicating whether to remember audio selections on played content. /// /// /// Required. /// public bool RememberAudioSelections { get; set; } /// /// Gets or sets a value indicating whether to remember subtitle selections on played content. /// /// /// Required. /// public bool RememberSubtitleSelections { get; set; } /// /// Gets or sets a value indicating whether to enable auto-play for the next episode. /// /// /// Required. /// public bool EnableNextEpisodeAutoPlay { get; set; } /// /// Gets or sets a value indicating whether the user should auto-login. /// /// /// Required. /// public bool EnableAutoLogin { get; set; } /// /// Gets or sets a value indicating whether the user can change their preferences. /// /// /// Required. /// public bool EnableUserPreferenceAccess { get; set; } /// /// Gets or sets the maximum parental age rating. /// public int? MaxParentalAgeRating { get; set; } /// /// Gets or sets the remote client bitrate limit. /// public int? RemoteClientBitrateLimit { get; set; } /// /// Gets or sets the internal id. /// This is a temporary stopgap for until the library db is migrated. /// This corresponds to the value of the index of this user in the library db. /// public long InternalId { get; set; } /// /// Gets or sets the user's profile image. Can be null. /// // [ForeignKey("UserId")] public virtual ImageInfo? ProfileImage { get; set; } /// /// Gets the user's display preferences. /// public virtual ICollection DisplayPreferences { get; private set; } /// /// Gets or sets the level of sync play permissions this user has. /// public SyncPlayUserAccessType SyncPlayAccess { get; set; } /// /// Gets or sets the cast receiver id. /// [StringLength(32)] public string? CastReceiverId { get; set; } /// [ConcurrencyCheck] public uint RowVersion { get; private set; } /// /// Gets the list of access schedules this user has. /// public virtual ICollection AccessSchedules { get; private set; } /// /// Gets the list of item display preferences. /// public virtual ICollection ItemDisplayPreferences { get; private set; } /* /// /// Gets the list of groups this user is a member of. /// public virtual ICollection Groups { get; private set; } */ /// /// Gets the list of permissions this user has. /// [ForeignKey("Permission_Permissions_Guid")] public virtual ICollection Permissions { get; private set; } /* /// /// Gets the list of provider mappings this user has. /// public virtual ICollection ProviderMappings { get; private set; } */ /// /// Gets the list of preferences this user has. /// [ForeignKey("Preference_Preferences_Guid")] public virtual ICollection Preferences { get; private set; } /// public void OnSavingChanges() { RowVersion++; } } }