postit: link to register and forgot-password from LoginPage
The Yavsc.Org sign-in page and the password-reset page are the canonical entry points for new users and locked-out users; expose both from PostIt's LoginPage by deriving their URLs from the configured Authentication.Authority. * Add RegisterUrl, ForgotPasswordUrl, HasXxxUrl, ConfigMissing and ConfigMissingMessage to LoginPageViewModel. * LoginPage loads settings eagerly in the VM ctor so the URLs are populated when XAML bindings first fire. * Two new buttons (Register a new account, Forgot password?) bind to HasXxxUrl via IsEnabled and fall back to Process.Start on click. * A yellow banner surfaces when Authentication.Authority is empty, pointing the user at ~/.config/PostIt/postit-settings.json. Also drop the duplicated OIDC login logic from LoginPage.axaml.cs: the page now drives Login through LoginPageViewModel.LoginAsync and DataContext is auto-attached when HomePage pushes the page without a VM. Tests cover the happy-path OIDC flow, URL derivation, and the ConfigMissing flag.
This commit is contained in:
parent
c411445699
commit
36e179c494
4 changed files with 196 additions and 61 deletions
|
|
@ -41,4 +41,64 @@ public class LoginPageViewModelTests
|
|||
vm.StatusMessage?.StartsWith("Error") == true,
|
||||
$"Login reported error: {vm.StatusMessage}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterUrl_and_ForgotPasswordUrl_are_derived_from_authority()
|
||||
{
|
||||
var settings = new PostIt.Settings
|
||||
{
|
||||
Authentication = new AuthenticationSettings
|
||||
{
|
||||
Authority = "https://yavsc.example.com/",
|
||||
ClientId = "postit-tests"
|
||||
},
|
||||
RedirectUri = "http://127.0.0.1:7890/",
|
||||
Scopes = new[] { "openid" }
|
||||
};
|
||||
|
||||
var vm = new LoginPageViewModel(settings);
|
||||
|
||||
// Trailing slash on Authority is normalised away.
|
||||
Assert.Equal(
|
||||
"https://yavsc.example.com/signin?ReturnUrl=~%2F&AllowRememberLogin=true",
|
||||
vm.RegisterUrl);
|
||||
Assert.Equal(
|
||||
"https://yavsc.example.com/Account/ForgotPassword",
|
||||
vm.ForgotPasswordUrl);
|
||||
Assert.True(vm.HasRegisterUrl);
|
||||
Assert.True(vm.HasForgotPasswordUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterUrl_is_empty_when_authority_is_unset()
|
||||
{
|
||||
var vm = new LoginPageViewModel(new PostIt.Settings());
|
||||
Assert.Equal(string.Empty, vm.RegisterUrl);
|
||||
Assert.Equal(string.Empty, vm.ForgotPasswordUrl);
|
||||
Assert.False(vm.HasRegisterUrl);
|
||||
Assert.False(vm.HasForgotPasswordUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigMissing_is_true_when_authority_is_unset()
|
||||
{
|
||||
var vm = new LoginPageViewModel(new PostIt.Settings());
|
||||
Assert.True(vm.ConfigMissing);
|
||||
Assert.Contains("~/.config/PostIt/postit-settings.json", vm.ConfigMissingMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfigMissing_is_false_when_authority_is_set()
|
||||
{
|
||||
var settings = new PostIt.Settings
|
||||
{
|
||||
Authentication = new AuthenticationSettings
|
||||
{
|
||||
Authority = "https://yavsc.example.com/",
|
||||
ClientId = "postit-tests"
|
||||
}
|
||||
};
|
||||
var vm = new LoginPageViewModel(settings);
|
||||
Assert.False(vm.ConfigMissing);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue