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
+60 -59
View File
@@ -1,63 +1,64 @@
<Blazorise.ThemeProvider Theme="@theme"> @using Blazorise.Components
<Router AppAssembly="typeof(App).Assembly"> <Blazorise.ThemeProvider Theme="@theme">
<Found Context="routeData"> <Router AppAssembly="typeof(App).Assembly">
<RouteView RouteData="routeData" DefaultLayout="typeof(Elektrifikatsiya.Layouts.MainLayout)" /> <Found Context="routeData">
</Found> <RouteView RouteData="routeData" DefaultLayout="typeof(Elektrifikatsiya.Layouts.MainLayout)" />
<NotFound> </Found>
<p>Sorry, there's nothing at this address.</p> <NotFound>
</NotFound> <p>Sorry, there's nothing at this address.</p>
</Router> </NotFound>
<MessageProvider /> </Router>
<NotificationProvider /> <MessageProvider />
<PageProgressProvider /> <NotificationProvider />
<PageProgressProvider />
</Blazorise.ThemeProvider> </Blazorise.ThemeProvider>
@code { @code {
private Theme theme = new() private Theme theme = new()
{ {
BarOptions = new() BarOptions = new()
{ {
HorizontalHeight = "72px", HorizontalHeight = "72px",
DarkColors = new() DarkColors = new()
{ {
ItemColorOptions = new() ItemColorOptions = new()
{ {
ActiveBackgroundColor = "#1a237e", ActiveBackgroundColor = "#1a237e",
ActiveColor = "#1a237e", ActiveColor = "#1a237e",
HoverColor = "#1a237e", HoverColor = "#1a237e",
} }
} }
}, },
ColorOptions = new() ColorOptions = new()
{ {
Primary = "#1a237e", Primary = "#1a237e",
Secondary = "#A65529", Secondary = "#A65529",
Success = "#23C02E", Success = "#23C02E",
Info = "#9BD8FE", Info = "#9BD8FE",
Warning = "#F8B86C", Warning = "#F8B86C",
Danger = "#F95741", Danger = "#F95741",
Light = "#F0F0F0", Light = "#F0F0F0",
Dark = "#535353", Dark = "#535353",
}, },
BackgroundOptions = new() BackgroundOptions = new()
{ {
Primary = "#1a237e", Primary = "#1a237e",
Secondary = "#A65529", Secondary = "#A65529",
Success = "#23C02E", Success = "#23C02E",
Info = "#9BD8FE", Info = "#9BD8FE",
Warning = "#F8B86C", Warning = "#F8B86C",
Danger = "#F95741", Danger = "#F95741",
Light = "#F0F0F0", Light = "#F0F0F0",
Dark = "#535353", Dark = "#535353",
}, },
InputOptions = new() InputOptions = new()
{ {
CheckColor = "#1a237e", CheckColor = "#1a237e",
}, },
TextColorOptions = new() TextColorOptions = new()
{ {
Dark = "#000000", Dark = "#000000",
Primary = "#1a237e" Primary = "#1a237e"
} }
}; };
} }
@@ -7,10 +7,13 @@ public class Device
{ {
[Key] [Key]
public string Key { get; private set; } public string Key { get; private set; }
[Required] [Required]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; }
[Required] [Required]
public IPAddress Address { get; private set; } public IPAddress Address { get; private set; }
public int PowerUsage { get; set; } public int PowerUsage { get; set; }
public string User { get; set; } public string User { get; set; }
public string Room { get; set; } public string Room { get; set; }
@@ -15,7 +15,9 @@ public interface IAuthenticationService
/// <summary> /// <summary>
/// Registers a new user. /// Registers a new user.
/// </summary> /// </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> /// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
Task<Result> RegisterUserAsync(string name, string password, Role role); Task<Result> RegisterUserAsync(string name, string password, Role role);
@@ -23,7 +25,8 @@ public interface IAuthenticationService
/// <summary> /// <summary>
/// Logs a user in. /// Logs a user in.
/// </summary> /// </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> /// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
Task<Result> LoginUserAsync(string name, string password); Task<Result> LoginUserAsync(string name, string password);
@@ -36,14 +39,13 @@ public interface IAuthenticationService
/// <summary> /// <summary>
/// Deletes the current user. /// Deletes the current user.
/// </summary> /// </summary>
/// <param name="deletionToken">The deletion token.</param> /// <returns>A <see cref="Task"/> to <see langword="await"/>.</returns>
/// <returns>A <see cref="Task"/> to <see langword="await"/> and a <see cref="bool"/> that indicates if the operation was successful.</returns>
Task<Result> DeleteUserAsync(); Task<Result> DeleteUserAsync();
/// <summary> /// <summary>
/// Checks if a user exists. /// Checks if a user exists.
/// </summary> /// </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> /// <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); Task<Result<bool>> UserExistsAsync(string name);
@@ -2,11 +2,24 @@
public static class TokenGenerator 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) public static string GenerateToken(string tokenType, int uid = 0, int length = 128)
{ {
return tokenType + "-" + SecureStringGenerator.CreateCryptographicRandomString(length, uid); 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) public static bool ValidateToken(string? token, string tokenType)
{ {
if (token is null) if (token is null)