fix(ldap): update user name and email during login

This commit is contained in:
kolaente 2025-03-20 17:24:00 +01:00
parent d585de77a4
commit 5a93379d81
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
2 changed files with 25 additions and 3 deletions

View File

@ -229,6 +229,30 @@ func getOrCreateLdapUser(s *xorm.Session, entry *ldap.Entry) (u *user.User, err
return auth.CreateUserWithRandomUsername(s, uu)
}
// Check if user information has changed and update if necessary
needsUpdate := false
if u.Email != email && email != "" {
u.Email = email
needsUpdate = true
}
if u.Name != name && name != "" {
u.Name = name
needsUpdate = true
}
if needsUpdate {
log.Debugf("Updating LDAP user information for %s", username)
_, err = s.Where("id = ?", u.ID).
Cols("email", "name").
Update(u)
if err != nil {
log.Errorf("Failed to update user information: %v", err)
return nil, err
}
}
return
}
@ -336,8 +360,6 @@ func cropAvatarTo1x1(imageData []byte) ([]byte, error) {
switch format {
case "jpeg":
err = jpeg.Encode(&buf, croppedImg, nil)
case "png":
err = png.Encode(&buf, croppedImg)
default:
// Default to PNG if format is unknown
err = png.Encode(&buf, croppedImg)

View File

@ -29,8 +29,8 @@ import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/modules/keyvalue"
"code.vikunja.io/api/pkg/notifications"
"code.vikunja.io/api/pkg/web"
"github.com/golang-jwt/jwt/v5"
"github.com/labstack/echo/v4"
"golang.org/x/crypto/bcrypt"