mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
33 lines
799 B
Go
33 lines
799 B
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/amir20/dozzle/internal/auth"
|
|
"github.com/amir20/dozzle/internal/profile"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (h *handler) saveSettings(w http.ResponseWriter, r *http.Request) {
|
|
var settings profile.Settings
|
|
if err := json.NewDecoder(r.Body).Decode(&settings); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
user := auth.RemoteUserFromContext(r.Context())
|
|
if user == nil {
|
|
http.Error(w, "Unable to find user", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
if err := profile.SaveUserSettings(user, &settings); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
log.Errorf("Unable to save user settings: %s", err)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
}
|