jellyfin/Jellyfin.Data/Entities/Security/Device.cs

108 lines
3.1 KiB
C#
Raw Normal View History

2021-04-10 03:16:07 +00:00
using System;
using System.ComponentModel.DataAnnotations;
2021-04-10 21:11:59 +00:00
using System.ComponentModel.DataAnnotations.Schema;
2021-05-21 00:57:10 +00:00
using System.Globalization;
2021-04-10 03:16:07 +00:00
namespace Jellyfin.Data.Entities.Security
{
/// <summary>
/// An entity representing a device.
/// </summary>
2021-09-03 00:18:46 +00:00
public class Device
2021-04-10 03:16:07 +00:00
{
/// <summary>
/// Initializes a new instance of the <see cref="Device"/> class.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="appName">The app name.</param>
/// <param name="appVersion">The app version.</param>
/// <param name="deviceName">The device name.</param>
/// <param name="deviceId">The device id.</param>
2021-05-21 00:57:10 +00:00
public Device(Guid userId, string appName, string appVersion, string deviceName, string deviceId)
2021-04-10 03:16:07 +00:00
{
UserId = userId;
AppName = appName;
AppVersion = appVersion;
DeviceName = deviceName;
DeviceId = deviceId;
2021-05-21 00:57:10 +00:00
AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
2021-04-10 03:16:07 +00:00
DateCreated = DateTime.UtcNow;
2021-08-14 00:35:31 +00:00
DateModified = DateCreated;
2021-04-10 03:16:07 +00:00
DateLastActivity = DateCreated;
// Non-nullable for EF Core, as this is a required relationship.
User = null!;
2021-04-10 03:16:07 +00:00
}
2021-04-10 21:11:59 +00:00
/// <summary>
/// Gets the id.
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2021-04-10 03:16:07 +00:00
public int Id { get; private set; }
/// <summary>
/// Gets the user id.
/// </summary>
public Guid UserId { get; private set; }
2021-04-14 00:01:31 +00:00
/// <summary>
/// Gets or sets the access token.
/// </summary>
public string AccessToken { get; set; }
2021-04-10 03:16:07 +00:00
/// <summary>
/// Gets or sets the app name.
/// </summary>
[MaxLength(64)]
[StringLength(64)]
public string AppName { get; set; }
/// <summary>
/// Gets or sets the app version.
/// </summary>
[MaxLength(32)]
[StringLength(32)]
public string AppVersion { get; set; }
/// <summary>
/// Gets or sets the device name.
/// </summary>
[MaxLength(64)]
[StringLength(64)]
public string DeviceName { get; set; }
/// <summary>
/// Gets or sets the device id.
/// </summary>
[MaxLength(256)]
[StringLength(256)]
public string DeviceId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this device is active.
/// </summary>
public bool IsActive { get; set; }
2021-09-03 00:18:46 +00:00
/// <summary>
/// Gets or sets the date created.
/// </summary>
public DateTime DateCreated { get; set; }
2021-04-10 03:16:07 +00:00
2021-09-03 00:18:46 +00:00
/// <summary>
/// Gets or sets the date modified.
/// </summary>
2021-08-14 00:35:31 +00:00
public DateTime DateModified { get; set; }
2021-04-10 03:16:07 +00:00
/// <summary>
/// Gets or sets the date of last activity.
/// </summary>
public DateTime DateLastActivity { get; set; }
/// <summary>
/// Gets the user.
/// </summary>
public User User { get; private set; }
2021-04-10 03:16:07 +00:00
}
}