Add authentication and authorization (#21)

Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
2025-04-21 01:53:58 +02:00
parent 51dab81121
commit 033747899b
55 changed files with 2186 additions and 317 deletions

View File

@@ -2,6 +2,18 @@
public class GlobalConstants
{
public static int NUMBER_PER_PAGE = 50;
public readonly static Guid ADMINISTRATOR_ID = Guid.Parse("{06CA5CB7-6DE5-4A73-9DDD-8E2D5CCDF104}");
public readonly static Guid ADMINISTRATOR_USER_ID = Guid.Parse("{2AB56FCB-0CDE-4DAE-AC9C-FC7635B0D18A}");
public readonly static Guid MEMBER_ID = Guid.Parse("{BCE14DEA-1748-4A76-8485-ADEE83DF5EFD}");
public const string ADMINISTRATOR = "Administrateur";
public const string MEMBER = "Membre";
public const string ADMIN_MEMBER = $"{ADMINISTRATOR}, {MEMBER}";
public const int JWT_DURATION_HOUR = 12;
public const int NUMBER_PER_PAGE = 50;
public const string LS_AUTH_STORAGE_KEY = "authToken";
}

View File

@@ -6,9 +6,9 @@ public class GameDetailDto
public string? Title { get; set; }
public DateTime? ReleaseDate { get; set; }
public DateTime? CreationDate { get; set; }
public int CreationUserId { get; set; }
public string CreationUserId { get; set; } = string.Empty;
public DateTime? ModificationDate { get; set; }
public int? ModificationUserId { get; set; }
public string? ModificationUserId { get; set; }
public double? StorageSpace { get; set; }
public string? Description { get; set; }
public int Interest { get; set; } = 3;

View File

@@ -1,11 +0,0 @@
using GameIdeas.Shared.Enum;
namespace GameIdeas.Shared.Dto;
public class LoginDto
{
public int? Id { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public Role? Role { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace GameIdeas.Shared.Dto;
public class TokenDto
{
public string? Token { get; set; }
public DateTime? Expiration { get; set; }
}

View File

@@ -7,5 +7,5 @@ public class UserDto
public int? Id { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public Role? Role { get; set; }
public string? RoleId { get; set; }
}

View File

@@ -1,8 +0,0 @@
namespace GameIdeas.Shared.Enum;
public enum Role
{
Guest = 1,
Member = 2,
Administrator = 3
}

View File

@@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.4" />
</ItemGroup>
</Project>

View File

@@ -15,9 +15,9 @@ public partial class Game
public string Title { get; set; } = null!;
public DateTime? ReleaseDate { get; set; }
public DateTime CreationDate { get; set; }
public int CreationUserId { get; set; }
public string CreationUserId { get; set; } = null!;
public DateTime? ModificationDate { get; set; }
public int? ModificationUserId { get; set; }
public string? ModificationUserId { get; set; }
public double? StorageSpace { get; set; }
public string? Description { get; set; }
public int Interest { get; set; }

View File

@@ -1,6 +1,8 @@
namespace GameIdeas.Shared.Model;
using Microsoft.AspNetCore.Identity;
public partial class User
namespace GameIdeas.Shared.Model;
public partial class User : IdentityUser
{
public User()
{
@@ -8,11 +10,6 @@ public partial class User
ModificationGames = new HashSet<Game>();
}
public int Id { get; set; }
public string Username { get; set; } = null!;
public string Password { get; set; } = null!;
public int Role { get; set; }
public virtual ICollection<Game> CreationGames { get; set; }
public virtual ICollection<Game> ModificationGames { get; set; }
}