Skip to content

Refactor Login page to use MediatR commands/queries#1320

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/refactor-login-index-class
Apr 12, 2026
Merged

Refactor Login page to use MediatR commands/queries#1320
StuartFerguson merged 3 commits intomasterfrom
copilot/refactor-login-index-class

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

The Login IndexModel had SignInManager<ApplicationUser> injected directly into the page model constructor. This refactors it to dispatch through MediatR, consistent with the rest of the application.

Changes

  • ExternalProviderDetails model added to SecurityService.Models for use across the business logic layer
  • GetExternalProvidersQuery added to SecurityServiceQueries — retrieves external auth schemes sorted by display name
  • LoginCommand added to SecurityServiceCommands — takes Username, Password, RememberLogin
  • LoginRequestHandler (new) — handles both the query and command via SignInManager; distinguishes IsLockedOut, IsNotAllowed, and RequiresTwoFactor states with specific error messages rather than a generic failure
  • Login/Index.cshtml.cs — constructor now takes only IMediator; failure messages from the handler are surfaced directly to ModelState
  • LoginPageModelTests — updated to mock IMediator instead of SignInManager
// Before
public IndexModel(SignInManager<ApplicationUser> signInManager) { ... }

// After
public IndexModel(IMediator mediator) { ... }

// Handler dispatched on POST
var result = await this._mediator.Send(
    new SecurityServiceCommands.LoginCommand(Input.Username, Input.Password, Input.RememberLogin));

The handler is auto-discovered via the existing RegisterServicesFromAssembly(typeof(SecurityServiceCommands).Assembly) in Program.cs — no DI wiring changes required.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.slnx --configuration Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore SecurityService.UnitTests/SecurityService.UnitTests.csproj (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 12, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · -1 duplication

Metric Results
Complexity 8
Duplication -1

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copilot AI and others added 2 commits April 12, 2026 11:55
Copilot AI changed the title [WIP] Refactor login index class to use commands and queries Refactor Login page to use MediatR commands/queries Apr 12, 2026
Copilot AI requested a review from StuartFerguson April 12, 2026 12:00
@StuartFerguson StuartFerguson marked this pull request as ready for review April 12, 2026 12:12
@StuartFerguson StuartFerguson merged commit 264fa41 into master Apr 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Login Page Refactor

2 participants