The pages built so far now live inside the shell of the mockups instead of the M0 placeholder, every interface text comes from Resources/it-IT, and each user keeps their own look and start page. - Shell: top bar, collapsible side menu with fly-out sub-menus, status bar and tabs that keep each page alive (page type and route values per tab, so a tab never shows another page); at most 12 tabs, least-used clean tab evicted. - One shortcut table with Alt variants for the combinations browsers keep (Ctrl+W, Ctrl+Tab, Ctrl+N); command palette for pages and commands. - ITexts over embedded JSON; tests forbid literal texts in .razor components and check that every key used exists. - User settings in sys_user_settings / user_settings; theme written on the server; profile page with live preview, start page, sessions and shortcuts. - Home, coming-soon pages for later milestones, localized sign-in and error pages; ADR 0020; wiki, CHANGELOG, STATUS and data model updated. Refs #25 #26 #31 #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
4.1 KiB
Plaintext
117 lines
4.1 KiB
Plaintext
@page "/login"
|
|
@attribute [ExcludeFromInteractiveRouting]
|
|
@layout AuthLayout
|
|
@using Khaemhat.Application.Licensing
|
|
@using Khaemhat.Application.Security
|
|
@using Khaemhat.Core.Instance
|
|
@using Khaemhat.Data.Companies
|
|
@inject SignInService SignIn
|
|
@inject ICompanyRegistry Companies
|
|
@inject ILicenseGate Licenses
|
|
@inject SecurityPolicyOptions Policy
|
|
@inject NavigationManager Navigation
|
|
@inject TimeProvider Clock
|
|
|
|
<PageTitle>@T["Auth.Login.Title"] · @T["Common.ProductName"]</PageTitle>
|
|
|
|
<h1>@T["Auth.Login.Title"]</h1>
|
|
<p class="sub">@T["Auth.Login.Subtitle"]</p>
|
|
|
|
@foreach (var message in Errors)
|
|
{
|
|
<div class="kh-alert err" role="alert">@message</div>
|
|
}
|
|
|
|
<EditForm Model="Input" method="post" FormName="login" OnSubmit="SubmitAsync" class="kh-form">
|
|
<label for="company">@T["Auth.Login.Company"]</label>
|
|
<InputSelect id="company" @bind-Value="Input.CompanyCode">
|
|
<option value="">@T["Auth.Login.NoCompany"]</option>
|
|
@foreach (var company in AvailableCompanies)
|
|
{
|
|
<option value="@company.Code">@T.Format("Auth.Login.CompanyOption", company.Name, company.Code)</option>
|
|
}
|
|
</InputSelect>
|
|
|
|
<label for="user">@T["Auth.Login.UserName"]</label>
|
|
<InputText id="user" @bind-Value="Input.UserName" autocomplete="username" autofocus required />
|
|
|
|
<label for="password">@T["Auth.Login.Password"]</label>
|
|
<InputText id="password" type="password" @bind-Value="Input.Password" autocomplete="current-password" required />
|
|
|
|
<label class="check"><InputCheckbox @bind-Value="Input.Remember" /> @T["Auth.Login.Remember"]</label>
|
|
|
|
<button type="submit" class="kh-btn primary">@T["Auth.Login.Submit"]</button>
|
|
</EditForm>
|
|
|
|
@if (TrialNotice is not null)
|
|
{
|
|
<div class="kh-alert warn">@TrialNotice</div>
|
|
}
|
|
|
|
@code {
|
|
[CascadingParameter]
|
|
private HttpContext HttpContext { get; set; } = default!;
|
|
|
|
[SupplyParameterFromForm]
|
|
private LoginInput Input { get; set; } = default!;
|
|
|
|
[SupplyParameterFromQuery]
|
|
private string? ReturnUrl { get; set; }
|
|
|
|
private IReadOnlyList<Company> AvailableCompanies { get; set; } = [];
|
|
|
|
private IReadOnlyList<string> Errors { get; set; } = [];
|
|
|
|
private string? TrialNotice { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Input ??= new LoginInput();
|
|
AvailableCompanies = [.. (await Companies.ListAsync(HttpContext.RequestAborted)).Where(c => c.Status is CompanyStatus.Active or CompanyStatus.ReadOnly)];
|
|
if (HttpMethods.IsGet(HttpContext.Request.Method) && string.IsNullOrEmpty(Input.CompanyCode))
|
|
{
|
|
Input.CompanyCode = AvailableCompanies.FirstOrDefault(c => c.IsDefault)?.Code;
|
|
}
|
|
|
|
var license = Licenses.Current;
|
|
if (license.Kind == LicenseKind.Trial)
|
|
{
|
|
TrialNotice = T.Format("Auth.Login.Trial", license.DaysLeft(Clock.GetUtcNow().UtcDateTime), license.MaxConcurrentUsers);
|
|
}
|
|
else if (license.Status != LicenseStatus.Valid)
|
|
{
|
|
TrialNotice = T["Auth.Login.Expired"];
|
|
}
|
|
}
|
|
|
|
private async Task SubmitAsync()
|
|
{
|
|
var request = new SignInRequest(
|
|
Input.CompanyCode, Input.UserName ?? string.Empty, Input.Password ?? string.Empty, Input.Remember,
|
|
HttpContext.Connection.RemoteIpAddress?.ToString(), HttpContext.Request.Headers.UserAgent.ToString());
|
|
var result = await SignIn.SignInAsync(request, HttpContext.RequestAborted);
|
|
Input.Password = null;
|
|
if (!result.Succeeded || result.Cookie is null)
|
|
{
|
|
Errors = LoginFlow.Messages(T, Policy, result.Error);
|
|
return;
|
|
}
|
|
|
|
var persistent = result.State == SessionState.Active && Input.Remember ? Clock.GetUtcNow() + Policy.PersistentSessionLifetime : (DateTimeOffset?)null;
|
|
SessionCookie.Write(HttpContext, result.Cookie, persistent);
|
|
Navigation.NavigateTo(LoginFlow.NextPage(result.State, ReturnUrl));
|
|
}
|
|
|
|
private sealed class LoginInput
|
|
{
|
|
public string? CompanyCode { get; set; }
|
|
|
|
public string? UserName { get; set; }
|
|
|
|
public string? Password { get; set; }
|
|
|
|
public bool Remember { get; set; }
|
|
}
|
|
}
|