From 97dcdbebf4d1e4042a8f8f443e171ef26cb41952 Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Sun, 29 Sep 2024 17:05:54 +0200 Subject: [PATCH 1/2] redirectiion added --- .../Layout/EmptyLayout.razor.css | 1 - .../WatchIt.Website/Layout/MainLayout.razor | 5 +- .../WatchIt.Website/Pages/AuthPage.razor | 91 +++++++++---------- .../WatchIt.Website/Pages/AuthPage.razor.cs | 54 +++++------ .../WatchIt.Website/Pages/AuthPage.razor.css | 8 ++ 5 files changed, 81 insertions(+), 78 deletions(-) delete mode 100644 WatchIt.Website/WatchIt.Website/Layout/EmptyLayout.razor.css diff --git a/WatchIt.Website/WatchIt.Website/Layout/EmptyLayout.razor.css b/WatchIt.Website/WatchIt.Website/Layout/EmptyLayout.razor.css deleted file mode 100644 index 5f28270..0000000 --- a/WatchIt.Website/WatchIt.Website/Layout/EmptyLayout.razor.css +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor index 7473c33..46f957f 100644 --- a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor +++ b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor @@ -1,4 +1,5 @@ -@using WatchIt.Common.Model.Photos +@using System.Net +@using WatchIt.Common.Model.Photos @using WatchIt.Website.Services.WebAPI.Photos @inherits LayoutComponentBase @@ -42,7 +43,7 @@
@if (_user is null) { - Sign in + Sign in } else { diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor index 42b5202..ce91e78 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor @@ -1,8 +1,7 @@ @page "/auth" @layout EmptyLayout -WatchIt - @(_authType == AuthType.SignIn ? "Sign in" : "Sign up") - +WatchIt - @(_isSingUp ? "Sign up" : "Sign in") @@ -10,38 +9,11 @@ {
-
- @if (_authType == AuthType.SignIn) - { -
- -
- -
-
- -
-
- -
-
- -
- - } - else + @if (_isSingUp) {
@@ -74,6 +46,33 @@
} + else + { +
+ +
+ +
+
+ +
+
+ +
+
+ +
+ + }
@if (_errors is not null) { @@ -87,31 +86,31 @@ }
- - - - + } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs index d2b5b85..965a23e 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; +using System.Net; +using Microsoft.AspNetCore.Components; using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Photos; @@ -26,26 +27,24 @@ public partial class AuthPage - #region ENUMS - - private enum AuthType - { - SignIn, - SignUp - } + #region PARAMETERS + [SupplyParameterFromQuery(Name = "redirect_to")] + private string RedirectTo { get; set; } = "/"; + #endregion #region FIELDS - private bool _loaded = false; + private bool _loaded; - private AuthType _authType = AuthType.SignIn; - private string _background = "assets/background_temp.jpg"; - private string _firstGradientColor = "#c6721c"; - private string _secondGradientColor = "#85200c"; + private PhotoResponse? _background; + + private bool _isSingUp; + + private AuthenticateRequest _loginModel = new AuthenticateRequest { @@ -75,22 +74,19 @@ public partial class AuthPage { if (await AuthenticationService.GetAuthenticationStatusAsync()) { - NavigationManager.NavigateTo("/"); + NavigationManager.NavigateTo(WebUtility.UrlDecode(RedirectTo)); } - - Action backgroundSuccess = (data) => - { - string imageBase64 = Convert.ToBase64String(data.Image); - string firstColor = BitConverter.ToString(data.Background.FirstGradientColor) - .Replace("-", string.Empty); - string secondColor = BitConverter.ToString(data.Background.SecondGradientColor) - .Replace("-", string.Empty); - _background = $"data:{data.MimeType};base64,{imageBase64}"; - _firstGradientColor = $"#{firstColor}"; - _secondGradientColor = $"#{secondColor}"; - }; - await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess); + List endTasks = new List(); + + // STEP 0 + endTasks.AddRange( + [ + PhotosWebAPIService.GetPhotoRandomBackground(data => _background = data) + ]); + + // END + await Task.WhenAll(endTasks); _loaded = true; StateHasChanged(); @@ -104,7 +100,7 @@ public partial class AuthPage async void LoginSuccess(AuthenticateResponse data) { await TokensService.SaveAuthenticationData(data); - NavigationManager.NavigateTo("/"); + NavigationManager.NavigateTo(RedirectTo); } void LoginBadRequest(IDictionary data) @@ -130,7 +126,7 @@ public partial class AuthPage void RegisterSuccess(RegisterResponse data) { - _authType = AuthType.SignIn; + _isSingUp = false; } void RegisterBadRequest(IDictionary data) diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.css b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.css index 35fd5d3..0d8700d 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.css +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.css @@ -4,6 +4,14 @@ html { height: 100%; } +body { + background-position: center; + background-repeat: no-repeat; + background-size: cover; + + height: 100%; +} + /* CLASSES */ From 662789395fd5f4398052f616daa61b1219c2c253 Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Sun, 29 Sep 2024 18:54:08 +0200 Subject: [PATCH 2/2] auth page renewed, fix in MainLayout --- WatchIt.Website/WatchIt.Website/App.razor | 2 +- .../WatchIt.Website/Layout/MainLayout.razor | 4 +- .../WatchIt.Website/Pages/AuthPage.razor | 152 +++++++++--------- .../WatchIt.Website/Pages/AuthPage.razor.cs | 67 ++++---- 4 files changed, 114 insertions(+), 111 deletions(-) diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index 35cf53c..2992e8c 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -11,7 +11,7 @@ - + diff --git a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor index 46f957f..ca49395 100644 --- a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor +++ b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor @@ -28,9 +28,7 @@ - - cancel_icon - + } else { diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor index ce91e78..39efc0c 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor @@ -8,98 +8,98 @@ @if (_loaded) {
-
- -
+
+
+ @if (_isSingUp) { -
+ -
- +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ @_formMessage +
+
+ +
+
-
- -
-
- -
-
- -
-
- -
- + } else { -
+ -
- +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + +
+
+
+
+
+ @_formMessage +
+
+ +
+
-
- -
-
- -
-
- -
- + } -
- @if (_errors is not null) - { -
- @foreach (string error in _errors) - { - @error -
- } +
+ + + +
- } -
- -
- + } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs index 965a23e..d646264 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs @@ -43,24 +43,22 @@ public partial class AuthPage private PhotoResponse? _background; private bool _isSingUp; + private string? _formMessage; + private bool _formMessageIsSuccess; - - - private AuthenticateRequest _loginModel = new AuthenticateRequest - { - UsernameOrEmail = null, - Password = null - }; - private RegisterRequest _registerModel = new RegisterRequest { Username = null, Email = null, Password = null }; - private string _passwordConfirmation; - - private IEnumerable _errors; + private string _registerPasswordConfirmation; + + private AuthenticateRequest _loginModel = new AuthenticateRequest + { + UsernameOrEmail = null, + Password = null + }; #endregion @@ -95,44 +93,51 @@ public partial class AuthPage private async Task Login() { - await AccountsWebAPIService.Authenticate(_loginModel, LoginSuccess, LoginBadRequest, LoginUnauthorized); + void LoginBadRequest(IDictionary data) + { + _formMessageIsSuccess = false; + _formMessage = data.SelectMany(x => x.Value).FirstOrDefault(); + } + + void LoginUnauthorized() + { + _formMessageIsSuccess = false; + _formMessage = "Incorrect account data"; + } - async void LoginSuccess(AuthenticateResponse data) + async Task LoginSuccess(AuthenticateResponse data) { await TokensService.SaveAuthenticationData(data); NavigationManager.NavigateTo(RedirectTo); } - void LoginBadRequest(IDictionary data) - { - _errors = data.SelectMany(x => x.Value).Select(x => $"• {x}"); - } - void LoginUnauthorized() - { - _errors = [ "Incorrect account data" ]; - } + await AccountsWebAPIService.Authenticate(_loginModel, async (data) => await LoginSuccess(data), LoginBadRequest, LoginUnauthorized); } private async Task Register() { - if (_registerModel.Password != _passwordConfirmation) - { - _errors = [ "Password fields don't match" ]; - return; - } - - await AccountsWebAPIService.Register(_registerModel, RegisterSuccess, RegisterBadRequest); - void RegisterSuccess(RegisterResponse data) { + _formMessageIsSuccess = true; + _formMessage = "You are registered. You can sign in now."; _isSingUp = false; } - + void RegisterBadRequest(IDictionary data) { - _errors = data.SelectMany(x => x.Value).Select(x => $"• {x}"); + _formMessageIsSuccess = false; + _formMessage = data.SelectMany(x => x.Value).FirstOrDefault(); } + + + if (_registerModel.Password != _registerPasswordConfirmation) + { + _formMessageIsSuccess = false; + _formMessage = "Password fields don't match"; + return; + } + await AccountsWebAPIService.Register(_registerModel, RegisterSuccess, RegisterBadRequest); } #endregion