| | | 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 an API key. |
| | | 10 | | /// </summary> |
| | | 11 | | public class ApiKey |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="ApiKey"/> class. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="name">The name.</param> |
| | | 17 | | public ApiKey(string name) |
| | | 18 | | { |
| | 0 | 19 | | Name = name; |
| | | 20 | | |
| | 0 | 21 | | AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); |
| | 0 | 22 | | DateCreated = DateTime.UtcNow; |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the id. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <remarks> |
| | | 29 | | /// Identity, Indexed, Required. |
| | | 30 | | /// </remarks> |
| | | 31 | | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] |
| | | 32 | | public int Id { get; private set; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets or sets the date created. |
| | | 36 | | /// </summary> |
| | | 37 | | public DateTime DateCreated { get; set; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets or sets the date of last activity. |
| | | 41 | | /// </summary> |
| | | 42 | | public DateTime DateLastActivity { get; set; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets or sets the name. |
| | | 46 | | /// </summary> |
| | | 47 | | [MaxLength(64)] |
| | | 48 | | [StringLength(64)] |
| | | 49 | | public string Name { get; set; } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets or sets the access token. |
| | | 53 | | /// </summary> |
| | | 54 | | public string AccessToken { get; set; } |
| | | 55 | | } |
| | | 56 | | } |