Always use lowercase username, as it is used for referential integrity. Fixes #352

This commit is contained in:
Deluan 2020-06-14 20:20:10 -04:00
parent 2d1d992e17
commit a6af46dbad
3 changed files with 5 additions and 4 deletions

View File

@ -38,7 +38,7 @@ func (p *players) Register(ctx context.Context, id, client, typ, ip string) (*mo
if err != nil || id == "" {
plr, err = p.ds.Player(ctx).FindByName(client, userName)
if err == nil {
log.Debug("Found player by name", "id", plr.ID, "client", client, "userName", userName)
log.Debug("Found player by name", "id", plr.ID, "client", client, "username", userName)
} else {
r, _ := uuid.NewRandom()
plr = &model.Player{
@ -47,7 +47,7 @@ func (p *players) Register(ctx context.Context, id, client, typ, ip string) (*mo
UserName: userName,
Client: client,
}
log.Info("Registering new player", "id", plr.ID, "client", client, "userName", userName)
log.Info("Registering new player", "id", plr.ID, "client", client, "username", userName)
}
}
plr.LastSeen = time.Now()

View File

@ -2,6 +2,7 @@ package request
import (
"context"
"strings"
"github.com/deluan/navidrome/model"
)
@ -22,7 +23,7 @@ func WithUser(ctx context.Context, u model.User) context.Context {
}
func WithUsername(ctx context.Context, username string) context.Context {
return context.WithValue(ctx, Username, username)
return context.WithValue(ctx, Username, strings.ToLower(username))
}
func WithClient(ctx context.Context, client string) context.Context {

View File

@ -105,7 +105,7 @@ func getPlayer(players engine.Players) func(next http.Handler) http.Handler {
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
player, trc, err := players.Register(ctx, playerId, client, r.Header.Get("user-agent"), ip)
if err != nil {
log.Error("Could not register player", "userName", userName, "client", client)
log.Error("Could not register player", "username", userName, "client", client)
} else {
ctx = request.WithPlayer(ctx, *player)
if trc != nil {