make login case insensitive

This commit is contained in:
Hayden 2023-02-03 12:10:04 -09:00
parent 7b28973c60
commit 6c2d1fd60f
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 3 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package v1
import ( import (
"errors" "errors"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/hay-kot/homebox/backend/internal/core/services" "github.com/hay-kot/homebox/backend/internal/core/services"
@ -70,7 +71,7 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
) )
} }
newToken, err := ctrl.svc.User.Login(r.Context(), loginForm.Username, loginForm.Password) newToken, err := ctrl.svc.User.Login(r.Context(), strings.ToLower(loginForm.Username), loginForm.Password)
if err != nil { if err != nil {
return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError) return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError)

View file

@ -69,7 +69,7 @@ func (e *UserRepository) GetOneId(ctx context.Context, id uuid.UUID) (UserOut, e
func (e *UserRepository) GetOneEmail(ctx context.Context, email string) (UserOut, error) { func (e *UserRepository) GetOneEmail(ctx context.Context, email string) (UserOut, error) {
return mapUserOutErr(e.db.User.Query(). return mapUserOutErr(e.db.User.Query().
Where(user.Email(email)). Where(user.EmailEqualFold(email)).
WithGroup(). WithGroup().
Only(ctx), Only(ctx),
) )