diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Database/UserDatabaseContext.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Database/UserDatabaseContext.cs new file mode 100644 index 0000000..917764f --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Database/UserDatabaseContext.cs @@ -0,0 +1,10 @@ +using Elektrifikatsiya.Models; + +using Microsoft.EntityFrameworkCore; + +namespace Elektrifikatsiya.Database; + +public class UserDatabaseContext : DbContext +{ + public DbSet Users { get; set; } +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj b/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj index 6b1a00c..e04bc06 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj @@ -20,7 +20,13 @@ + + + + + + diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Models/Role.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Role.cs new file mode 100644 index 0000000..f2afd89 --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Role.cs @@ -0,0 +1,7 @@ +namespace Elektrifikatsiya.Models; + +public enum Role +{ + Admin, + User +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Models/User.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Models/User.cs new file mode 100644 index 0000000..99fc256 --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Models/User.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Elektrifikatsiya.Models; + +public class User +{ + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key] + public int Id { get; private set; } + + public string Name { get; private set; } + public string PasswordHash { get; private set; } + public string? SessionToken { get; set; } + public DateTime LastLoginDate { get; set; } + + public User(string name, string passwordHash) + { + Name = name; + PasswordHash = passwordHash; + } +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs index 44ecc11..d9004c1 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Program.cs @@ -25,12 +25,8 @@ app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); - -app.UseEndpoints(endpoints => -{ - _ = endpoints.MapBlazorHub(); - _ = endpoints.MapFallbackToPage("/_Host"); -}); +app.MapBlazorHub(); +app.MapFallbackToPage("/_Host"); app.Run(); diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthenticationService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthenticationService.cs new file mode 100644 index 0000000..ac34b36 --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthenticationService.cs @@ -0,0 +1,53 @@ +using Elektrifikatsiya.Models; + +namespace Elektrifikatsiya.Services; + +public interface IAuthenticationService +{ + /// + /// Gets the current user. + /// + /// to and the currently authenticated user. + Task GetUserAsync(); + + /// + /// Registers a new user. + /// + /// The E-mail address of the user. + /// A to . + + Task RegisterUserAsync(string name, string password); + + /// + /// Logs a user in. + /// + /// The E-mail address of the user. + /// A to . + Task<(bool Success, string? Message)> LoginUserAsync(string name, string password); + + /// + /// Logs the user out. + /// + /// A to . + Task LogoutUserAsync(); + + /// + /// Deletes the current user. + /// + /// The deletion token. + /// A to and a that indicates if the operation was successful. + Task DeleteUserAsync(string deletionToken); + + /// + /// Checks if a user exists. + /// + /// The E-mail address of the user. + /// A to and a that indicates if the user exists. + Task UserExistsAsync(string name); + + /// + /// Check if the current user is authenticated. + /// + /// A to and a that indicates if the user is authenticated. + Task IsAuthenticated(); +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthorizationService.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthorizationService.cs new file mode 100644 index 0000000..223d9c8 --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Services/IAuthorizationService.cs @@ -0,0 +1,13 @@ +using Elektrifikatsiya.Models; + +namespace Elektrifikatsiya.Services; + +public interface IAuthorizationService +{ + /// + /// Check if the current user is authorized. + /// + /// The minimum required role. + /// A to and a that indicates if the user is authorized. + Task IsAuthorized(Role requiredRole); +} \ No newline at end of file