renaming, spinner in MediaFormControl poster section added
This commit is contained in:
@@ -7,7 +7,7 @@ using WatchIt.Website.Services.WebAPI.Media;
|
|||||||
|
|
||||||
namespace WatchIt.Website.Components;
|
namespace WatchIt.Website.Components;
|
||||||
|
|
||||||
public partial class MediaForm : ComponentBase
|
public partial class MediaFormComponent : ComponentBase
|
||||||
{
|
{
|
||||||
#region SERVICES
|
#region SERVICES
|
||||||
|
|
||||||
6
WatchIt.Website/WatchIt.Website/Pages/AdminPage.razor.cs
Normal file
6
WatchIt.Website/WatchIt.Website/Pages/AdminPage.razor.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace WatchIt.Website.Pages;
|
||||||
|
|
||||||
|
public class AdminPage_razor
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,4 @@
|
|||||||
@page "/auth"
|
@page "/auth"
|
||||||
@using System.Text
|
|
||||||
@using WatchIt.Common.Model.Accounts
|
|
||||||
@using WatchIt.Common.Model.Media
|
|
||||||
@using WatchIt.Website.Services.Utility.Authentication
|
|
||||||
@using WatchIt.Website.Services.Utility.Tokens
|
|
||||||
@using WatchIt.Website.Services.WebAPI.Accounts
|
|
||||||
@using WatchIt.Website.Services.WebAPI.Media
|
|
||||||
@layout EmptyLayout
|
@layout EmptyLayout
|
||||||
|
|
||||||
<PageTitle>WatchIt - @(_authType == AuthType.SignIn ? "Sign in" : "Sign up")</PageTitle>
|
<PageTitle>WatchIt - @(_authType == AuthType.SignIn ? "Sign in" : "Sign up")</PageTitle>
|
||||||
@@ -127,134 +120,3 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@code
|
|
||||||
{
|
|
||||||
#region SERVICES
|
|
||||||
|
|
||||||
[Inject] public ILogger<Auth> Logger { get; set; } = default!;
|
|
||||||
[Inject] public IAuthenticationService AuthenticationService { get; set; } = default!;
|
|
||||||
[Inject] public ITokensService TokensService { get; set; } = default!;
|
|
||||||
[Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
|
|
||||||
[Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!;
|
|
||||||
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region ENUMS
|
|
||||||
|
|
||||||
private enum AuthType
|
|
||||||
{
|
|
||||||
SignIn,
|
|
||||||
SignUp
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region FIELDS
|
|
||||||
|
|
||||||
private bool _loaded = false;
|
|
||||||
|
|
||||||
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 RegisterRequest _registerModel = new RegisterRequest
|
|
||||||
{
|
|
||||||
Username = null,
|
|
||||||
Email = null,
|
|
||||||
Password = null
|
|
||||||
};
|
|
||||||
private string _passwordConfirmation;
|
|
||||||
|
|
||||||
private IEnumerable<string> _errors;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region METHODS
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
if (await AuthenticationService.GetAuthenticationStatusAsync())
|
|
||||||
{
|
|
||||||
NavigationManager.NavigateTo("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
Action<MediaPhotoResponse> 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 MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
|
|
||||||
|
|
||||||
_loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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<string, string[]> data)
|
|
||||||
{
|
|
||||||
_errors = data.SelectMany(x => x.Value).Select(x => $"• {x}");
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoginUnauthorized()
|
|
||||||
{
|
|
||||||
_errors = [ "Incorrect account data" ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterBadRequest(IDictionary<string, string[]> data)
|
|
||||||
{
|
|
||||||
_errors = data.SelectMany(x => x.Value).Select(x => $"• {x}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
136
WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs
Normal file
136
WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using WatchIt.Common.Model.Accounts;
|
||||||
|
using WatchIt.Common.Model.Media;
|
||||||
|
using WatchIt.Website.Services.Utility.Authentication;
|
||||||
|
using WatchIt.Website.Services.Utility.Tokens;
|
||||||
|
using WatchIt.Website.Services.WebAPI.Accounts;
|
||||||
|
using WatchIt.Website.Services.WebAPI.Media;
|
||||||
|
|
||||||
|
namespace WatchIt.Website.Pages;
|
||||||
|
|
||||||
|
public partial class AuthPage
|
||||||
|
{
|
||||||
|
#region SERVICES
|
||||||
|
|
||||||
|
[Inject] public ILogger<AuthPage> Logger { get; set; } = default!;
|
||||||
|
[Inject] public IAuthenticationService AuthenticationService { get; set; } = default!;
|
||||||
|
[Inject] public ITokensService TokensService { get; set; } = default!;
|
||||||
|
[Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
|
||||||
|
[Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!;
|
||||||
|
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region ENUMS
|
||||||
|
|
||||||
|
private enum AuthType
|
||||||
|
{
|
||||||
|
SignIn,
|
||||||
|
SignUp
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region FIELDS
|
||||||
|
|
||||||
|
private bool _loaded = false;
|
||||||
|
|
||||||
|
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 RegisterRequest _registerModel = new RegisterRequest
|
||||||
|
{
|
||||||
|
Username = null,
|
||||||
|
Email = null,
|
||||||
|
Password = null
|
||||||
|
};
|
||||||
|
private string _passwordConfirmation;
|
||||||
|
|
||||||
|
private IEnumerable<string> _errors;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region METHODS
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
if (await AuthenticationService.GetAuthenticationStatusAsync())
|
||||||
|
{
|
||||||
|
NavigationManager.NavigateTo("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
Action<MediaPhotoResponse> 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 MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
|
||||||
|
|
||||||
|
_loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<string, string[]> data)
|
||||||
|
{
|
||||||
|
_errors = data.SelectMany(x => x.Value).Select(x => $"• {x}");
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginUnauthorized()
|
||||||
|
{
|
||||||
|
_errors = [ "Incorrect account data" ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegisterBadRequest(IDictionary<string, string[]> data)
|
||||||
|
{
|
||||||
|
_errors = data.SelectMany(x => x.Value).Select(x => $"• {x}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
6
WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs
Normal file
6
WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace WatchIt.Website.Pages;
|
||||||
|
|
||||||
|
public class HomePage_razor
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user