updated to use bun and updated hws modules.

This commit is contained in:
2026-01-11 23:39:10 +11:00
parent 6e03c98ae8
commit 1eedbc5220
33 changed files with 984 additions and 375 deletions

View File

@@ -2,28 +2,30 @@ package handler
import (
"context"
"database/sql"
"net/http"
"time"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/hwsauth"
"projectreshoot/internal/models"
"projectreshoot/internal/view/component/form"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/hwsauth"
"github.com/pkg/errors"
"github.com/uptrace/bun"
)
// Validate the provided password
func validatePassword(
auth *hwsauth.Authenticator[*models.User],
tx *sql.Tx,
ctx context.Context,
auth *hwsauth.Authenticator[*models.UserBun, bun.Tx],
tx bun.Tx,
r *http.Request,
) error {
r.ParseForm()
password := r.FormValue("password")
user := auth.CurrentModel(r.Context())
err := user.CheckPassword(tx, password)
err := user.CheckPassword(ctx, tx, password)
if err != nil {
return errors.Wrap(err, "user.CheckPassword")
}
@@ -33,8 +35,8 @@ func validatePassword(
// Handle request to reauthenticate (i.e. make token fresh again)
func Reauthenticate(
server *hws.Server,
auth *hwsauth.Authenticator[*models.User],
conn *sql.DB,
auth *hwsauth.Authenticator[*models.UserBun, bun.Tx],
db *bun.DB,
) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
@@ -42,7 +44,7 @@ func Reauthenticate(
defer cancel()
// Start the transaction
tx, err := conn.BeginTx(ctx, nil)
tx, err := db.BeginTx(ctx, nil)
if err != nil {
err := server.ThrowError(w, r, hws.HWSError{
StatusCode: http.StatusInternalServerError,
@@ -55,7 +57,7 @@ func Reauthenticate(
return
}
defer tx.Rollback()
err = validatePassword(auth, tx, r)
err = validatePassword(ctx, auth, tx, r)
if err != nil {
w.WriteHeader(445)
form.ConfirmPassword("Incorrect password").Render(r.Context(), w)