feat(07-02): throttle failed logins and pick mail template locale

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-09-22 14:03:31 +02:00
parent 1311bd6cad
commit 00e6c51abd
7 changed files with 322 additions and 23 deletions

View File

@@ -35,7 +35,31 @@ func (g GormUsers) FindByID(ctx context.Context, id uint) (*bouncer.Principal, e
if err != nil {
return nil, err
}
return &bouncer.Principal{ID: row.ID, MustChangePassword: row.MustChangePassword}, nil
principal := &bouncer.Principal{ID: row.ID, MustChangePassword: row.MustChangePassword}
if row.PreferredLocale != nil {
principal.PreferredLocale = *row.PreferredLocale
}
if row.TokensValidAfter != nil {
principal.TokensValidAfter = *row.TokensValidAfter
}
return principal, nil
}
// LookupByEmail returns the user row, including a soft-deleted one.
// A missing email is (nil, nil).
func LookupByEmail(ctx context.Context, db *gorm.DB, email string) (*models.User, error) {
if db == nil {
return nil, fmt.Errorf("golem15.user: gorm handle is missing")
}
var row models.User
err := db.WithContext(ctx).Unscoped().Where("email = ?", email).Take(&row).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &row, nil
}
// JWTSecret reads golem15.user.jwt.secret and fails loudly when it is empty.