redirectiion added
This commit is contained in:
@@ -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 @@
|
||||
<div class="float-end">
|
||||
@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
|
||||
{
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
@page "/auth"
|
||||
@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="d-inline-flex flex-column justify-content-center panel panel-header rounded-3">
|
||||
<a class="logo" href="/">
|
||||
<a id="logo" class="logo" href="/">
|
||||
WatchIt
|
||||
</a>
|
||||
<div>
|
||||
@if (_authType == AuthType.SignIn)
|
||||
{
|
||||
<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
|
||||
@if (_isSingUp)
|
||||
{
|
||||
<form method="post" @onsubmit="Register" @formname="register">
|
||||
<AntiforgeryToken/>
|
||||
@@ -74,6 +46,33 @@
|
||||
</div>
|
||||
</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>
|
||||
@if (_errors is not null)
|
||||
{
|
||||
@@ -87,31 +86,31 @@
|
||||
}
|
||||
<div>
|
||||
<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
|
||||
</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
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
/* TAGS */
|
||||
|
||||
body {
|
||||
height: 100%;
|
||||
|
||||
background-image: url('@_background');
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
background-image: url('@(_background is null ? "assets/background_temp.jpg": _background.ToString())');
|
||||
}
|
||||
|
||||
.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>
|
||||
}
|
||||
@@ -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<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}";
|
||||
_firstGradientColor = $"#{firstColor}";
|
||||
_secondGradientColor = $"#{secondColor}";
|
||||
};
|
||||
await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
|
||||
List<Task> endTasks = new List<Task>();
|
||||
|
||||
// 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<string, string[]> data)
|
||||
@@ -130,7 +126,7 @@ public partial class AuthPage
|
||||
|
||||
void RegisterSuccess(RegisterResponse data)
|
||||
{
|
||||
_authType = AuthType.SignIn;
|
||||
_isSingUp = false;
|
||||
}
|
||||
|
||||
void RegisterBadRequest(IDictionary<string, string[]> data)
|
||||
|
||||
@@ -4,6 +4,14 @@ html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* CLASSES */
|
||||
|
||||
Reference in New Issue
Block a user