Merge pull request #28 from Stefan-5422/feature-login_service

Feature login service
This commit is contained in:
Stone_Red
2023-02-22 09:09:25 +01:00
committed by GitHub
5 changed files with 91 additions and 66 deletions
@@ -1,4 +1,5 @@
<Blazorise.ThemeProvider Theme="@theme">
@using Blazorise.Components
<Blazorise.ThemeProvider Theme="@theme">
<Router AppAssembly="typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Elektrifikatsiya.Layouts.MainLayout)" />
@@ -17,6 +17,13 @@
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Model\**" />
<Content Remove="Model\**" />
<EmbeddedResource Remove="Model\**" />
<None Remove="Model\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blazorise" Version="1.2.0" />
<PackageReference Include="Blazorise.Charts" Version="1.2.0" />
@@ -32,7 +39,6 @@
<ItemGroup>
<Folder Include="Middleware\" />
<Folder Include="Model\" />
</ItemGroup>
</Project>
@@ -7,10 +7,13 @@ public class Device
{
[Key]
public string Key { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
public string Name { get; private set; }
[Required]
public IPAddress Address { get; private set; }
public int PowerUsage { get; set; }
public string User { get; set; }
public string Room { get; set; }
@@ -15,7 +15,9 @@ public interface IAuthenticationService
/// <summary>
/// Registers a new user.
/// </summary>
/// <param name="email">The E-mail address of the user.</param>
/// <param name="name">The name address of the user.</param>
/// <param name="password">The password of the user.</param>
/// <param name="role">The default role of the user.</param>
/// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
Task<Result> RegisterUserAsync(string name, string password, Role role);
@@ -23,7 +25,8 @@ public interface IAuthenticationService
/// <summary>
/// Logs a user in.
/// </summary>
/// <param name="name">The E-mail address of the user.</param>
/// <param name="name">The name of the user.</param>
/// <param name="password">The password of the user.</param>
/// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
Task<Result> LoginUserAsync(string name, string password);
@@ -36,14 +39,13 @@ public interface IAuthenticationService
/// <summary>
/// Deletes the current user.
/// </summary>
/// <param name="deletionToken">The deletion token.</param>
/// <returns>A <see cref="Task"/> to <see langword="await"/> and a <see cref="bool"/> that indicates if the operation was successful.</returns>
/// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
Task<Result> DeleteUserAsync();
/// <summary>
/// Checks if a user exists.
/// </summary>
/// <param name="name">The E-mail address of the user.</param>
/// <param name="name">The name address of the user.</param>
/// <returns>A <see cref="Task"/> to <see langword="await"/> and a <see cref="bool"/> that indicates if the user exists.</returns>
Task<Result<bool>> UserExistsAsync(string name);
@@ -2,11 +2,24 @@
public static class TokenGenerator
{
/// <summary>
/// Creates secure token and uses an UID to make it unique.
/// </summary>
/// <param name="tokenType">The type of the token.</param>
/// <param name="uid">The UID of a user.</param>
/// <param name="length">The length of the token.</param>
/// <returns></returns>
public static string GenerateToken(string tokenType, int uid = 0, int length = 128)
{
return tokenType + "-" + SecureStringGenerator.CreateCryptographicRandomString(length, uid);
}
/// <summary>
/// Checks if a token is valid.
/// </summary>
/// <param name="token">The token to validate.</param>
/// <param name="tokenType">The type the token should have.</param>
/// <returns></returns>
public static bool ValidateToken(string? token, string tokenType)
{
if (token is null)