Skip to content

Commit

Permalink
Merge branch 'fix-user-query'
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 21, 2024
2 parents 7847167 + e7109da commit 1075485
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"errors"
"net/http"
"net/mail"
"net/url"
"strings"
"time"
Expand Down Expand Up @@ -90,8 +92,20 @@ func handleOIDCFinish(c echo.Context) error {
return renderLoginPage(c, err)
}

// Validate e-mail from the claim.
email := strings.TrimSpace(claims.Email)
if email == "" {
return renderLoginPage(c, errors.New(app.i18n.Ts("globals.messages.invalidFields", "name", "email")))
}

em, err := mail.ParseAddress(email)
if err != nil {
return renderLoginPage(c, err)
}
email = strings.ToLower(em.Address)

// Get the user by e-mail received from OIDC.
user, err := app.core.GetUser(0, "", claims.Email)
user, err := app.core.GetUser(0, "", email)
if err != nil {
return renderLoginPage(c, err)
}
Expand Down
1 change: 1 addition & 0 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ FROM users
WHERE
(
CASE
-- either filter one row by id/username/text OR match all rows.
WHEN $1::INT != 0 THEN users.id = $1
WHEN $2::TEXT != '' THEN username = $2
WHEN $3::TEXT != '' THEN email = $3
Expand Down

0 comments on commit 1075485

Please sign in to comment.