refactor(api): one password rule, one hash, one unique-violation check (#8002)

The length check and bcrypt call were copied into sign-up, reset,
change and both admin paths; the unique-violation test into three api
handlers and the library. checkNewPassword and hashPassword now sit in
api/prelude.go, and db.IsUniqueViolation serves api and library. The
taken-username and taken-email conflicts now carry a message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 12:45:18 -05:00
co-authored by Claude Opus 5.5
parent cfdd6b916f
commit 074d9ffb0e
10 changed files with 66 additions and 55 deletions
+3 -2
View File
@@ -20,6 +20,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
syncpkg "git.fabledsword.com/bvandeusen/minstrel/internal/sync"
)
@@ -616,7 +617,7 @@ func (s *Scanner) resolveArtist(ctx context.Context, q *dbq.Queries, name, mbid
ID: existing.ID,
Mbid: &m,
}); uerr != nil {
if isUniqueViolation(uerr) {
if db.IsUniqueViolation(uerr) {
// Another artist row already owns this MBID — two rows that
// should be merged (usually two spellings of one name).
// Expected, not a fault: leave NULL and let an admin
@@ -687,7 +688,7 @@ func (s *Scanner) resolveAlbum(ctx context.Context, q *dbq.Queries, artistID pgt
ID: existing.ID,
Mbid: &m,
}); uerr != nil {
if isUniqueViolation(uerr) {
if db.IsUniqueViolation(uerr) {
// Another album row already owns this MBID — duplicate
// release in the DB. Leave NULL; operator merges later.
s.logger.Info("library scan: duplicate album mbid (canonical row already owns it)",