bug where a users profile photo would not display if the user had not

logged in
This commit is contained in:
2026-04-06 09:30:15 -04:00
parent 384ef90ea8
commit d0524f901c
2 changed files with 40 additions and 10 deletions

View File

@@ -98,7 +98,11 @@ func UploadPhotoHandler(w http.ResponseWriter, r *http.Request) {
return
}
userDN := fmt.Sprintf("uid=%s,cn=users,cn=accounts,%s", sessionData.UserID, BaseDN)
LDAPServer.ModifyAttribute(ServiceUserBindDN, ServiceUserPassword, userDN, "jpegphoto", []string{string(data)})
err = LDAPServer.ModifyAttribute(ServiceUserBindDN, ServiceUserPassword, userDN, "jpegphoto", []string{string(data)})
if err != nil {
logging.Error(err.Error())
return
}
CreateUserPhoto(sessionData.UserID, data)
}
@@ -112,17 +116,25 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
filePath := fmt.Sprintf("./avatars/%s.jpeg", username)
cleaned := filepath.Clean(filePath)
value, err := helpers.ReadFile(cleaned)
if err == nil {
photoCreatedMutex.Lock()
if time.Since(photoCreatedTimestamp[username]) <= 5*time.Minute {
photoCreatedMutex.Unlock()
w.Write(value)
fileExist, err := helpers.DoesFileExist(cleaned)
if err != nil {
w.Write(blankPhotoData)
logging.Error(err.Error())
return
}
photoCreatedMutex.Lock()
if fileExist && time.Since(photoCreatedTimestamp[username]) <= 5*time.Minute {
photoCreatedMutex.Unlock()
val, err := helpers.ReadFile(cleaned)
if err != nil {
logging.Error(err.Error())
w.Write(blankPhotoData)
return
}
photoCreatedMutex.Unlock()
w.Write(val)
return
}
photoCreatedMutex.Unlock()
userSearch, err := LDAPServer.SerchServer(
ServiceUserBindDN, ServiceUserPassword,
@@ -130,10 +142,16 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("(&(objectClass=inetOrgPerson)(uid=%s))", ldap.LDAPEscapeFilter(username)),
[]string{"jpegphoto"},
)
if err == nil || userSearch.EntryCount() == 0 {
if err != nil {
logging.Error(err.Error())
w.Write(blankPhotoData)
return
}
if userSearch.EntryCount() == 0 {
w.Write(blankPhotoData)
return
}
entry := userSearch.GetEntry(0)
bytes := entry.GetRawAttributeValue("jpegphoto")
if len(bytes) == 0 {
@@ -142,5 +160,6 @@ func AvatarHandler(w http.ResponseWriter, r *http.Request) {
} else {
w.Write(bytes)
CreateUserPhoto(username, bytes)
return
}
}