@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 Moonlight.App.Database.Entities @using Moonlight.App.Models.Misc @using Moonlight.App.Services.Sessions @using System.ComponentModel.DataAnnotations @using Moonlight.App.Helpers @using Moonlight.App.Models.Forms @inject AlertService AlertService @inject UserService UserService @inject SmartTranslateService SmartTranslateService @inject CookieService CookieService @inject NavigationManager NavigationManager @inject OAuth2Service OAuth2Service
@if (!TotpRequired) {

Sign In

Sign in to start with moonlight
@foreach (var providers in OAuth2Service.Providers.Chunk(2)) {
@foreach (var provider in providers) { }
} @if (OAuth2Service.Providers.Any()) {
Or with email
}
Not registered yet? Sign up
} else {
}
@code { private LoginDataModel LoginData = new(); private LoginTotpDataModel TotpData = new(); private bool TotpRequired = false; private async Task DoLogin() { try { LoginData.Email = LoginData.Email.ToLower().Trim(); if (string.IsNullOrEmpty(TotpData.Code)) { TotpRequired = await UserService.CheckTotp(LoginData.Email, LoginData.Password); if (!TotpRequired) { var token = await UserService.Login(LoginData.Email, LoginData.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); } } else { var token = await UserService.Login(LoginData.Email, LoginData.Password, TotpData.Code); await CookieService.SetValue("token", token, 10); if (NavigationManager.Uri.EndsWith("login")) NavigationManager.NavigateTo("/", true); else NavigationManager.NavigateTo(NavigationManager.Uri, true); } } catch (DisplayException e) { // Reset state LoginData = new(); TotpData = new(); TotpRequired = false; await AlertService.Error( SmartTranslateService.Translate("Error"), SmartTranslateService.Translate(e.Message) ); } catch (Exception e) { Logger.Error("Error while login"); Logger.Error(e); // Reset state LoginData = new(); TotpData = new(); TotpRequired = false; await AlertService.Error( SmartTranslateService.Translate("Error"), SmartTranslateService.Translate("An error occured while logging you in") ); } } private async Task StartOAuth2(string id) { var url = await OAuth2Service.GetUrl(id); NavigationManager.NavigateTo(url ,true); } }