Completion program R2, with PrivaPub's routes of the same release.
- Pages/PasswordRecovery.razor (/password-recovery): asks for a login or an address and shows the server's one
sentence; with ?rc= it takes the code out of the address bar at once, checks it and sets a new password. Login links
there ("Forgot your password?").
- Settings, the login: its email address with a verified badge, changed with the password and the code emailed to it
(DOtp), removed with the password; "Sign out everywhere" (every device and persona, asked first).
- A password change takes the new JWT PrivaPub answers and exchanges the persona's token again, since every persona
token ended with it.
- The theme kept with the login (PageSettings.SyncWithLogin, Settings > General): taken at sign-in and start-up once a
client saved it, saved 1.5 s after a change here, never posted back when nothing changed, never the language.
- Login, Setup and Join start the session through CascadingState.SignedIn, which takes the login's theme.
- 38 keys in both resx files; CLAUDE.md follows.
Verified: dotnet build decePubClient.csproj -c Release (0 errors, no new warnings).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WpVCoDeM1qUTRp4fXQdfof
91 lines
3.7 KiB
C#
91 lines
3.7 KiB
C#
|
|
using PrivaPub.ClientModels.Resources;
|
|
using PrivaPub.ClientModels.User;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace decePubClient.Models
|
|
{
|
|
public class PageSettings
|
|
{
|
|
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
|
|
Display(Name = "LanguageId", ResourceType = typeof(FieldsNameResource))]
|
|
public string CurrentLanguageCode { get; set; } = "en";
|
|
[Range(0, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
|
|
public short LightThemeIndexColour { get; set; } = 25;
|
|
[Range(0, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
|
|
public short DarkThemeIndexColour { get; set; } = 215;
|
|
|
|
public bool PreferSystemTheming { get; set; } = true;
|
|
public bool ThemeIsDarkMode { get; set; } = false;
|
|
public bool ThemeIsLightGray { get; set; } = true;
|
|
public bool ThemeIsDarkGray { get; set; } = false;
|
|
// before publishing pictures without a description, the composer asks once
|
|
public bool RemindAltText { get; set; } = true;
|
|
// the theme is the login's (PrivaPub's user settings): taken at sign-in, saved there whenever it changes here
|
|
public bool SyncWithLogin { get; set; } = true;
|
|
|
|
// How the theme flags combine is in wwwroot/js/theme.js: with PreferSystemTheming the OS picks light or dark;
|
|
// otherwise ThemeIsDarkGray, then ThemeIsLightGray, then ThemeIsDarkMode decide; either grey flag drops the
|
|
// colour. These keep the flags consistent when the UI changes one aspect.
|
|
|
|
public const short DefaultLightThemeIndexColour = 25;
|
|
public const short DefaultDarkThemeIndexColour = 215;
|
|
|
|
public bool IsGray() => ThemeIsLightGray || ThemeIsDarkGray;
|
|
|
|
/// <summary>Leaves system theming and shows the light or dark variant, grey or coloured as before.</summary>
|
|
public void SetDarkMode(bool isDark)
|
|
{
|
|
PreferSystemTheming = false;
|
|
ThemeIsDarkMode = isDark;
|
|
if (IsGray())
|
|
SetGray(true, isDark);
|
|
}
|
|
|
|
/// <summary>Switches grey on or off for the variant currently shown.</summary>
|
|
public void SetGray(bool isGray, bool isDark)
|
|
{
|
|
ThemeIsDarkGray = isGray && isDark;
|
|
ThemeIsLightGray = isGray && !isDark;
|
|
}
|
|
|
|
/// <summary>Sets the hue of the light or dark variant; picking a hue means colour, so grey goes off.</summary>
|
|
public void SetHue(bool isDark, short hue)
|
|
{
|
|
if (isDark)
|
|
DarkThemeIndexColour = hue;
|
|
else
|
|
LightThemeIndexColour = hue;
|
|
SetGray(false, isDark);
|
|
}
|
|
|
|
/// <summary>
|
|
/// These settings as the login keeps them: the language as the two letters of the culture the app runs in
|
|
/// (ExtensionMethods.ToCulture: "it" is it-IT, anything else en-GB), the icons' hue at its default, since the client
|
|
/// has no such setting.
|
|
/// </summary>
|
|
public ViewUserSettings ToLoginSettings() => new()
|
|
{
|
|
LanguageCode = CurrentLanguageCode is "it" ? "it" : "en",
|
|
LightThemeIndexColour = LightThemeIndexColour,
|
|
DarkThemeIndexColour = DarkThemeIndexColour,
|
|
IconsThemeIndexColour = DefaultLightThemeIndexColour,
|
|
PreferSystemTheming = PreferSystemTheming,
|
|
ThemeIsDarkMode = ThemeIsDarkMode,
|
|
ThemeIsLightGray = ThemeIsLightGray,
|
|
ThemeIsDarkGray = ThemeIsDarkGray
|
|
};
|
|
|
|
/// <summary>Takes the login's theme; its language stays this device's, since changing it reloads the app.</summary>
|
|
public void TakeLoginTheme(ViewUserSettings settings)
|
|
{
|
|
LightThemeIndexColour = Math.Clamp(settings.LightThemeIndexColour, (short)0, (short)359);
|
|
DarkThemeIndexColour = Math.Clamp(settings.DarkThemeIndexColour, (short)0, (short)359);
|
|
PreferSystemTheming = settings.PreferSystemTheming;
|
|
ThemeIsDarkMode = settings.ThemeIsDarkMode;
|
|
ThemeIsLightGray = settings.ThemeIsLightGray;
|
|
ThemeIsDarkGray = settings.ThemeIsDarkGray;
|
|
}
|
|
}
|
|
} |