mirror of
https://github.com/azukaar/Cosmos-Server.git
synced 2026-01-07 20:59:32 -06:00
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"net/http"
|
|
"encoding/json"
|
|
"github.com/gorilla/mux"
|
|
"../utils"
|
|
)
|
|
|
|
func ConfigApiSet(w http.ResponseWriter, req *http.Request) {
|
|
if AdminOnly(w, req) != nil {
|
|
return
|
|
}
|
|
|
|
if(req.Method == "PUT") {
|
|
var request utils.Config
|
|
err1 := json.NewDecoder(req.Body).Decode(&request)
|
|
if err1 != nil {
|
|
utils.Error("SettingsUpdate: Invalid User Request", err1)
|
|
utils.HTTPError(w, "User Creation Error",
|
|
http.StatusInternalServerError, "UC001")
|
|
return
|
|
}
|
|
|
|
errV := utils.Validate.Struct(request)
|
|
if errV != nil {
|
|
utils.Error("SettingsUpdate: Invalid User Request", errV)
|
|
utils.HTTPError(w, "User Creation Error: " + errV.Error(),
|
|
http.StatusInternalServerError, "UC003")
|
|
return
|
|
}
|
|
|
|
// restore AuthPrivateKey and TLSKey
|
|
config := utils.GetBaseMainConfig()
|
|
request.AuthPrivateKey = config.AuthPrivateKey
|
|
request.TLSKey = config.TLSKey
|
|
|
|
err := utils.SaveConfigTofile(request)
|
|
|
|
if err != nil {
|
|
utils.Error("SettingsUpdate: Error saving config to file", err)
|
|
utils.HTTPError(w, "Error saving config to file",
|
|
http.StatusInternalServerError, "CS001")
|
|
return
|
|
}
|
|
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"status": "OK"
|
|
})
|
|
} else {
|
|
utils.Error("SettingsUpdate: Method not allowed" + req.Method, nil)
|
|
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
|
|
return
|
|
}
|
|
}
|