diff --git a/Moonlight/App/Database/Entities/User.cs b/Moonlight/App/Database/Entities/User.cs index e0f45831..f99b8c60 100644 --- a/Moonlight/App/Database/Entities/User.cs +++ b/Moonlight/App/Database/Entities/User.cs @@ -19,12 +19,12 @@ public class User [MaxLength(64, ErrorMessage = "Max lenght reached")] public string LastName { get; set; } = ""; - [Required] - [RegularExpression(@"^((((([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)[;]?)+$", - ErrorMessage = "Must be a valid email")] - [MaxLength(128, ErrorMessage = "Max lenght reached")] + [Required(ErrorMessage = "You need to enter an email address")] + [EmailAddress(ErrorMessage = "You need to enter a valid email address")] public string Email { get; set; } = ""; + [Required(ErrorMessage = "You need to enter a password")] + [MinLength(8, ErrorMessage = "You need to enter a password with minimum 8 characters in lenght")] public string Password { get; set; } = ""; [Required] diff --git a/Moonlight/Shared/Components/Auth/Login.razor b/Moonlight/Shared/Components/Auth/Login.razor index ccf91770..f9b27e7f 100644 --- a/Moonlight/Shared/Components/Auth/Login.razor +++ b/Moonlight/Shared/Components/Auth/Login.razor @@ -9,6 +9,7 @@ @using Moonlight.App.Services @using Moonlight.App.Exceptions @using Logging.Net +@using Moonlight.App.Database.Entities @using Moonlight.App.Services.OAuth2 @using Moonlight.App.Services.Sessions @@ -24,10 +25,10 @@
-
+ @if (!TotpRequired) { -
+

Sign In

@@ -61,12 +62,12 @@
-
- +
+
-
- +
+
@@ -78,11 +79,9 @@
- - +
} else @@ -106,7 +105,7 @@ Sign up
-
+
@@ -114,8 +113,7 @@ @code { - private string Email = ""; - private string Password = ""; + private User User = new(); private bool TotpRequired = false; private string TotpCode = ""; @@ -124,16 +122,16 @@ { try { - Email = Email.ToLower().Trim(); - - TotpRequired = await UserService.CheckTotp(Email, Password); + User.Email = User.Email.ToLower().Trim(); + + TotpRequired = await UserService.CheckTotp(User.Email, User.Password); if (!TotpRequired) { - var token = await UserService.Login(Email, Password); + var token = await UserService.Login(User.Email, User.Password); await CookieService.SetValue("token", token, 10); - - if(NavigationManager.Uri.EndsWith("login")) + + if (NavigationManager.Uri.EndsWith("login")) NavigationManager.NavigateTo("/", true); else NavigationManager.NavigateTo(NavigationManager.Uri, true); @@ -167,7 +165,7 @@ var url = await GoogleOAuth2Service.GetUrl(); NavigationManager.NavigateTo(url, true); } - + private async Task DoDiscord() { var url = await DiscordOAuth2Service.GetUrl(); diff --git a/Moonlight/Shared/Components/Forms/SmartForm.razor b/Moonlight/Shared/Components/Forms/SmartForm.razor index 615ebef5..0eb23002 100644 --- a/Moonlight/Shared/Components/Forms/SmartForm.razor +++ b/Moonlight/Shared/Components/Forms/SmartForm.razor @@ -3,17 +3,27 @@
- @if (ErrorMessages.Any()) + @if (Working) { -
- @foreach (var msg in ErrorMessages) - { - @(msg) -
- } +
+ + Proccessing
} - @(ChildContent) + else + { + if (ErrorMessages.Any()) + { +
+ @foreach (var msg in ErrorMessages) + { + @(msg) +
+ } +
+ } + @(ChildContent) + }
@@ -21,16 +31,16 @@ { [Parameter] public object Model { get; set; } - - [Parameter] + + [Parameter] public EventCallback OnValidSubmit { get; set; } - + [Parameter] public EventCallback OnInvalidSubmit { get; set; } - + [Parameter] public EventCallback OnSubmit { get; set; } - + [Parameter] public RenderFragment ChildContent { get; set; } @@ -38,6 +48,8 @@ private List ErrorMessages = new(); + private bool Working = false; + protected override void OnAfterRender(bool firstRender) { if (firstRender) @@ -49,10 +61,18 @@ private async Task ValidSubmit(EditContext context) { ErrorMessages.Clear(); + Working = true; + await InvokeAsync(StateHasChanged); - await OnValidSubmit.InvokeAsync(context); - await OnSubmit.InvokeAsync(context); + await Task.Run(async () => + { + await InvokeAsync(() => OnValidSubmit.InvokeAsync(context)); + await InvokeAsync(() => OnSubmit.InvokeAsync(context)); + + Working = false; + await InvokeAsync(StateHasChanged); + }); } private async Task InvalidSubmit(EditContext context) @@ -66,7 +86,7 @@ } await InvokeAsync(StateHasChanged); - + await OnInvalidSubmit.InvokeAsync(context); await OnSubmit.InvokeAsync(context); } diff --git a/Moonlight/Shared/Components/Partials/Navbar.razor b/Moonlight/Shared/Components/Partials/Navbar.razor index 75bdcf65..9952884f 100644 --- a/Moonlight/Shared/Components/Partials/Navbar.razor +++ b/Moonlight/Shared/Components/Partials/Navbar.razor @@ -20,15 +20,9 @@ @if (User != null) {
-
- - - - - - - -
+ + +
diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 4c4a41a5..8f280dab 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -394,6 +394,11 @@ Discord id;Discord id Discord username;Discord username Discord discriminator;Discord discriminator The Name field is required.;The Name field is required. +An error occured while logging you in;An error occured while logging you in +You need to enter an email address;You need to enter an email address +You need to enter a password;You need to enter a password +You need to enter a password with minimum 8 characters in lenght;You need to enter a password with minimum 8 characters in lenght +Proccessing;Proccessing The FirstName field is required.;The FirstName field is required. The LastName field is required.;The LastName field is required. The Address field is required.;The Address field is required. @@ -401,4 +406,4 @@ The City field is required.;The City field is required. The State field is required.;The State field is required. The Country field is required.;The Country field is required. Street and house number requered;Street and house number requered -Max lenght reached;Max lenght reached +Max lenght reached;Max lenght reached \ No newline at end of file