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/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..ca49395 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 @@ -27,9 +28,7 @@ - - cancel_icon - + } else { @@ -42,7 +41,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..39efc0c 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor @@ -1,117 +1,116 @@ @page "/auth" @layout EmptyLayout -WatchIt - @(_authType == AuthType.SignIn ? "Sign in" : "Sign up") - +WatchIt - @(_isSingUp ? "Sign up" : "Sign in") @if (_loaded) {
-
- -
- @if (_authType == AuthType.SignIn) +
+
+ + @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 d2b5b85..d646264 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,42 +27,38 @@ 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 AuthenticateRequest _loginModel = new AuthenticateRequest - { - UsernameOrEmail = null, - Password = null - }; + private PhotoResponse? _background; + private bool _isSingUp; + private string? _formMessage; + private bool _formMessageIsSuccess; + 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 @@ -75,22 +72,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(); @@ -99,44 +93,51 @@ public partial class AuthPage private async Task Login() { - await AccountsWebAPIService.Authenticate(_loginModel, LoginSuccess, LoginBadRequest, LoginUnauthorized); - - async void LoginSuccess(AuthenticateResponse data) - { - await TokensService.SaveAuthenticationData(data); - NavigationManager.NavigateTo("/"); - } - void LoginBadRequest(IDictionary data) { - _errors = data.SelectMany(x => x.Value).Select(x => $"• {x}"); + _formMessageIsSuccess = false; + _formMessage = data.SelectMany(x => x.Value).FirstOrDefault(); } - + void LoginUnauthorized() { - _errors = [ "Incorrect account data" ]; + _formMessageIsSuccess = false; + _formMessage = "Incorrect account data"; } + + async Task LoginSuccess(AuthenticateResponse data) + { + await TokensService.SaveAuthenticationData(data); + NavigationManager.NavigateTo(RedirectTo); + } + + + 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) { - _authType = AuthType.SignIn; + _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 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 */