redirectiion added

This commit is contained in:
2024-09-29 17:05:54 +02:00
Unverified
parent f9cea4e8bf
commit 97dcdbebf4
5 changed files with 81 additions and 78 deletions

View File

@@ -1,4 +1,5 @@
@using WatchIt.Common.Model.Photos @using System.Net
@using WatchIt.Common.Model.Photos
@using WatchIt.Website.Services.WebAPI.Photos @using WatchIt.Website.Services.WebAPI.Photos
@inherits LayoutComponentBase @inherits LayoutComponentBase
@@ -42,7 +43,7 @@
<div class="float-end"> <div class="float-end">
@if (_user is null) @if (_user is null)
{ {
<a id="signInButton" class="main-button" href="/auth">Sign in</a> <a id="signInButton" class="main-button" href="/auth?redirect_to=@(WebUtility.UrlEncode(NavigationManager.Uri))">Sign in</a>
} }
else else
{ {

View File

@@ -1,8 +1,7 @@
@page "/auth" @page "/auth"
@layout EmptyLayout @layout EmptyLayout
<PageTitle>WatchIt - @(_authType == AuthType.SignIn ? "Sign in" : "Sign up")</PageTitle> <PageTitle>WatchIt - @(_isSingUp ? "Sign up" : "Sign in")</PageTitle>
@@ -10,38 +9,11 @@
{ {
<div class="h-100 d-flex align-items-center justify-content-center"> <div class="h-100 d-flex align-items-center justify-content-center">
<div class="d-inline-flex flex-column justify-content-center panel panel-header rounded-3"> <div class="d-inline-flex flex-column justify-content-center panel panel-header rounded-3">
<a class="logo" href="/"> <a id="logo" class="logo" href="/">
WatchIt WatchIt
</a> </a>
<div> <div>
@if (_authType == AuthType.SignIn) @if (_isSingUp)
{
<form method="post" @onsubmit="Login" @formname="login">
<AntiforgeryToken/>
<div>
<label>
Username or email:
<InputText @bind-Value="_loginModel!.UsernameOrEmail"/>
</label>
</div>
<div>
<label>
Password:
<InputText type="password" @bind-Value="_loginModel!.Password"/>
</label>
</div>
<div>
<label>
<InputCheckbox @bind-Value="_loginModel!.RememberMe"></InputCheckbox>
Remember me
</label>
</div>
<div>
<button type="submit">Sign in</button>
</div>
</form>
}
else
{ {
<form method="post" @onsubmit="Register" @formname="register"> <form method="post" @onsubmit="Register" @formname="register">
<AntiforgeryToken/> <AntiforgeryToken/>
@@ -74,6 +46,33 @@
</div> </div>
</form> </form>
} }
else
{
<form method="post" @onsubmit="Login" @formname="login">
<AntiforgeryToken/>
<div>
<label>
Username or email:
<InputText @bind-Value="_loginModel!.UsernameOrEmail"/>
</label>
</div>
<div>
<label>
Password:
<InputText type="password" @bind-Value="_loginModel!.Password"/>
</label>
</div>
<div>
<label>
<InputCheckbox @bind-Value="_loginModel!.RememberMe"></InputCheckbox>
Remember me
</label>
</div>
<div>
<button type="submit">Sign in</button>
</div>
</form>
}
</div> </div>
@if (_errors is not null) @if (_errors is not null)
{ {
@@ -87,31 +86,31 @@
} }
<div> <div>
<label> <label>
<input type="radio" checked="@(() => _authType == AuthType.SignIn)" name="auth" @onchange="@(() => _authType = AuthType.SignIn)" /> <input type="radio" checked="@(() => !_isSingUp)" name="auth" @onchange="@(() => _isSingUp = false)" />
Sign in Sign in
</label> </label>
<label> <label>
<input type="radio" checked="@(() => _authType == AuthType.SignUp)" name="auth" @onchange="@(() => _authType = AuthType.SignUp)" /> <input type="radio" checked="@(() => _isSingUp)" name="auth" @onchange="@(() => _isSingUp = true)" />
Sign up Sign up
</label> </label>
</div> </div>
</div> </div>
</div> </div>
<style> <style>
/* TAGS */
body { body {
height: 100%; background-image: url('@(_background is null ? "assets/background_temp.jpg": _background.ToString())');
background-image: url('@_background');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
} }
.logo {
background-image: linear-gradient(45deg, @_firstGradientColor, @_secondGradientColor); /* IDS */
#logo {
background-image: linear-gradient(45deg, @(_background is null ? "#c6721c, #85200c" : $"#{Convert.ToHexString(_background.Background.FirstGradientColor)}, #{Convert.ToHexString(_background.Background.SecondGradientColor)}"));
} }
</style> </style>
} }

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components; using System.Net;
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Accounts;
using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Photos;
@@ -26,26 +27,24 @@ public partial class AuthPage
#region ENUMS #region PARAMETERS
private enum AuthType
{
SignIn,
SignUp
}
[SupplyParameterFromQuery(Name = "redirect_to")]
private string RedirectTo { get; set; } = "/";
#endregion #endregion
#region FIELDS #region FIELDS
private bool _loaded = false; private bool _loaded;
private AuthType _authType = AuthType.SignIn; private PhotoResponse? _background;
private string _background = "assets/background_temp.jpg";
private string _firstGradientColor = "#c6721c"; private bool _isSingUp;
private string _secondGradientColor = "#85200c";
private AuthenticateRequest _loginModel = new AuthenticateRequest private AuthenticateRequest _loginModel = new AuthenticateRequest
{ {
@@ -75,22 +74,19 @@ public partial class AuthPage
{ {
if (await AuthenticationService.GetAuthenticationStatusAsync()) if (await AuthenticationService.GetAuthenticationStatusAsync())
{ {
NavigationManager.NavigateTo("/"); NavigationManager.NavigateTo(WebUtility.UrlDecode(RedirectTo));
} }
Action<PhotoResponse> 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}"; List<Task> endTasks = new List<Task>();
_firstGradientColor = $"#{firstColor}";
_secondGradientColor = $"#{secondColor}"; // STEP 0
}; endTasks.AddRange(
await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess); [
PhotosWebAPIService.GetPhotoRandomBackground(data => _background = data)
]);
// END
await Task.WhenAll(endTasks);
_loaded = true; _loaded = true;
StateHasChanged(); StateHasChanged();
@@ -104,7 +100,7 @@ public partial class AuthPage
async void LoginSuccess(AuthenticateResponse data) async void LoginSuccess(AuthenticateResponse data)
{ {
await TokensService.SaveAuthenticationData(data); await TokensService.SaveAuthenticationData(data);
NavigationManager.NavigateTo("/"); NavigationManager.NavigateTo(RedirectTo);
} }
void LoginBadRequest(IDictionary<string, string[]> data) void LoginBadRequest(IDictionary<string, string[]> data)
@@ -130,7 +126,7 @@ public partial class AuthPage
void RegisterSuccess(RegisterResponse data) void RegisterSuccess(RegisterResponse data)
{ {
_authType = AuthType.SignIn; _isSingUp = false;
} }
void RegisterBadRequest(IDictionary<string, string[]> data) void RegisterBadRequest(IDictionary<string, string[]> data)

View File

@@ -4,6 +4,14 @@ html {
height: 100%; height: 100%;
} }
body {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
}
/* CLASSES */ /* CLASSES */