Added new node manager. Added new login/register screen. AuditLog. Permissions
This commit is contained in:
161
Moonlight/Shared/Components/Auth/Login.razor
Normal file
161
Moonlight/Shared/Components/Auth/Login.razor
Normal file
@@ -0,0 +1,161 @@
|
||||
@page "/login"
|
||||
|
||||
@* This is just a "virtual" route/page. The handling for that is
|
||||
@* MainLayout doing for us. We need to put that here so the router
|
||||
@* does not return the 404 page
|
||||
*@
|
||||
|
||||
@using Moonlight.App.Services.Interop
|
||||
@using Moonlight.App.Services
|
||||
@using Moonlight.App.Exceptions
|
||||
@using Logging.Net
|
||||
@using Moonlight.App.Services.Sessions
|
||||
|
||||
@inject AlertService AlertService
|
||||
@inject UserService UserService
|
||||
@inject SmartTranslateService SmartTranslateService
|
||||
@inject CookieService CookieService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<div class="d-flex flex-center">
|
||||
<div class="card rounded-3 w-md-550px">
|
||||
<div class="card-body">
|
||||
<div class="d-flex flex-center flex-column-fluid pb-15 pb-lg-20">
|
||||
<div class="form w-100 fv-plugins-bootstrap5 fv-plugins-framework" novalidate="novalidate">
|
||||
@if (!TotpRequired)
|
||||
{
|
||||
<div class="text-center mb-11">
|
||||
<h1 class="text-dark fw-bolder mb-3">
|
||||
<TL>Sign In</TL>
|
||||
</h1>
|
||||
<div class="text-gray-500 fw-semibold fs-6">
|
||||
<TL>Sign in to start with moonlight</TL>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-9">
|
||||
<div class="col-md-6">
|
||||
<a href="#" class="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100">
|
||||
<div class="h-15px me-3">
|
||||
<i class="bx bx-md bxl-discord-alt"></i>
|
||||
</div>
|
||||
<TL>Sign in with Discord</TL>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<a href="#" class="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100">
|
||||
<div class="h-15px me-3">
|
||||
<i class="bx bx-md bxl-google"></i>
|
||||
</div>
|
||||
<TL>Sign in with Google</TL>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="separator separator-content my-14">
|
||||
<span class="w-125px text-gray-500 fw-semibold fs-7">
|
||||
<TL>Or with email</TL>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-8 fv-plugins-icon-container">
|
||||
<input @bind="Email" type="text" placeholder="@(SmartTranslateService.Translate("Email"))" class="form-control bg-transparent">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-3 fv-plugins-icon-container">
|
||||
<input @bind="Password" type="password" placeholder="@(SmartTranslateService.Translate("Password"))" class="form-control bg-transparent">
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack flex-wrap gap-3 fs-base fw-semibold mb-8">
|
||||
<div></div>
|
||||
|
||||
<a href="/reset-password" class="link-primary">
|
||||
<TL>Forgot password?</TL>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="d-grid mb-10">
|
||||
<WButton Text="@(SmartTranslateService.Translate("Sign-in"))"
|
||||
WorkingText="@(SmartTranslateService.Translate("Working"))"
|
||||
CssClasses="btn-primary"
|
||||
OnClick="DoLogin">
|
||||
</WButton>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="fv-row mb-8 fv-plugins-icon-container">
|
||||
<input type="number" class="form-control bg-transparent">
|
||||
</div>
|
||||
<div class="d-grid mb-10">
|
||||
<WButton Text="@(SmartTranslateService.Translate("Sign-in"))"
|
||||
WorkingText="@(SmartTranslateService.Translate("Working"))"
|
||||
CssClasses="btn-primary"
|
||||
OnClick="DoLogin">
|
||||
</WButton>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="text-gray-500 text-center fw-semibold fs-6">
|
||||
<TL>Not registered yet?</TL>
|
||||
|
||||
<a href="/register" class="link-primary">
|
||||
<TL>Sign up</TL>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private string Email = "";
|
||||
private string Password = "";
|
||||
|
||||
private bool TotpRequired = false;
|
||||
private string TotpCode = "";
|
||||
|
||||
private async Task DoLogin()
|
||||
{
|
||||
try
|
||||
{
|
||||
Email = Email.ToLower().Trim();
|
||||
|
||||
TotpRequired = await UserService.CheckTotp(Email, Password);
|
||||
|
||||
if (!TotpRequired)
|
||||
{
|
||||
var token = await UserService.Login(Email, Password);
|
||||
await CookieService.SetValue("token", token, 10);
|
||||
|
||||
if(NavigationManager.Uri.EndsWith("login"))
|
||||
NavigationManager.NavigateTo("/", true);
|
||||
else
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
catch (DisplayException e)
|
||||
{
|
||||
await AlertService.Error(
|
||||
SmartTranslateService.Translate("Error"),
|
||||
SmartTranslateService.Translate(e.Message)
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await AlertService.Error(
|
||||
SmartTranslateService.Translate("Error"),
|
||||
SmartTranslateService.Translate("An error occured while logging you in")
|
||||
);
|
||||
|
||||
Logger.Error("Error while login");
|
||||
Logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user