This commit is contained in:
Stone_Red
2023-02-21 18:39:07 +01:00
parent b9e7f40dac
commit 0a003f7aa7
4 changed files with 84 additions and 65 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)" />
@@ -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)