Added Authentication with user-auth and apikey-auth
This commit is contained in:
35
watcher-monitoring/Models/ApiKey.cs
Normal file
35
watcher-monitoring/Models/ApiKey.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace watcher_monitoring.Models;
|
||||
|
||||
public class ApiKey
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(64)]
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime? ExpiresAt { get; set; }
|
||||
|
||||
public DateTime? LastUsedAt { get; set; }
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public bool IsExpired => ExpiresAt.HasValue && ExpiresAt.Value < DateTime.UtcNow;
|
||||
|
||||
// Foreign Key: Jeder API-Key gehört zu einem User
|
||||
public int UserId { get; set; }
|
||||
|
||||
// Navigation Property
|
||||
public User User { get; set; } = null!;
|
||||
}
|
||||
18
watcher-monitoring/Models/LoginViewModel.cs
Normal file
18
watcher-monitoring/Models/LoginViewModel.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace watcher_monitoring.Models;
|
||||
|
||||
public class LoginViewModel
|
||||
{
|
||||
[Required(ErrorMessage = "Benutzername ist erforderlich")]
|
||||
[Display(Name = "Benutzername")]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
|
||||
[Required(ErrorMessage = "Passwort ist erforderlich")]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Passwort")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Display(Name = "Angemeldet bleiben")]
|
||||
public bool RememberMe { get; set; }
|
||||
}
|
||||
@@ -22,4 +22,11 @@ public class User
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public required string Password { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
// Navigation Property: Ein User kann mehrere API-Keys haben
|
||||
public ICollection<ApiKey> ApiKeys { get; set; } = new List<ApiKey>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user