Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/handlers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"errors"
"fmt"
"github.com/The127/Keyline/config"
"github.com/The127/Keyline/internal/authentication"
"github.com/The127/Keyline/internal/commands"
"github.com/The127/Keyline/internal/database"
"github.com/The127/Keyline/internal/jsonTypes"
Expand Down Expand Up @@ -621,8 +622,14 @@ func ResetTemporaryPassword(w http.ResponseWriter, r *http.Request) {
return err
}

// The login flow is pre-authentication, so /logins/* skips
// authentication.Middleware and ctx carries no CurrentUser. Switch
// to the system identity for this command: the login token plus the
// LoginStepTemporaryPassword guard above are the proof that the
// caller is authorised to reset their own temp password.
sysCtx := authentication.ContextWithCurrentUser(ctx, authentication.SystemUser())
m := ioc.GetDependency[mediatr.Mediator](scope)
_, err = mediatr.Send[*commands.SetPasswordResponse](ctx, m, commands.SetPassword{
_, err = mediatr.Send[*commands.SetPasswordResponse](sysCtx, m, commands.SetPassword{
UserId: loginInfo.UserId,
NewPassword: dto.NewPassword,
Temporary: false,
Expand Down