From 97dcdbebf4d1e4042a8f8f443e171ef26cb41952 Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Sun, 29 Sep 2024 17:05:54 +0200 Subject: [PATCH] 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 */