rewrite using net/http
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 5s
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 5s
This commit is contained in:
1 parent
db8ed2e830
commit
98790dbe3b
9 files changed
+270
-189
No files matched your search
+17
-7
@@ -1,13 +1,13 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
paas "proxmoxaas-common-lib"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
|
||||
"github.com/gerow/go-color"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
@@ -40,29 +40,39 @@ var Green = color.RGB{
|
||||
B: 0,
|
||||
}
|
||||
|
||||
func HandleGETAccount(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETAccount(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
user, err := GetUserBasic(auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
pools, err := GetUserPools(auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "html/account.html", gin.H{
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/account.html", map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "account",
|
||||
"user": user,
|
||||
"pools": pools,
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
||||
http.Redirect(w, r, "/login", http.StatusFound) // if user is not authed, redirect user to login page
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-19
@@ -1,13 +1,13 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
paas "proxmoxaas-common-lib"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
@@ -20,61 +20,78 @@ type InstanceBackup struct {
|
||||
TimeFormatted string
|
||||
}
|
||||
|
||||
func HandleGETBackups(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETBackups(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
backups, err := GetInstanceBackups(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance backups: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance backups: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth) // only used for the VM's name
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "html/backups.html", gin.H{
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/index.html", map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "backups",
|
||||
"backups": backups,
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETBackupsFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETBackupsFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil { // user should be authed, try to return index with population
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
backups, err := GetInstanceBackups(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance backups: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance backups: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/backups-backups.go.tmpl", gin.H{
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/backups-backups.go.tmpl", map[string]any{
|
||||
"backups": backups,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else { // return 401
|
||||
c.Status(http.StatusUnauthorized)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+84
-52
@@ -1,6 +1,7 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
paas "proxmoxaas-common-lib"
|
||||
@@ -8,7 +9,6 @@ import (
|
||||
"slices"
|
||||
"sort"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
@@ -31,24 +31,26 @@ type PoolConfig struct {
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETConfig(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETConfig(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if config.Type == "VM" { // if VM, fetch CPU types from node
|
||||
config.ProctypeSelect, err = GetCPUTypes(vm_path, config.Pool, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting proctypes: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting proctypes: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
for i, cpu := range config.ProctypeSelect.Options {
|
||||
@@ -57,125 +59,155 @@ func HandleGETConfig(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "html/config.html", gin.H{
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/config.html", map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "config",
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETConfigVolumesFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETConfigVolumesFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/config-volumes.go.tmpl", gin.H{
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/config-volumes.go.tmpl", map[string]any{
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETConfigNetsFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETConfigNetsFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/config-nets.go.tmpl", gin.H{
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/config-nets.go.tmpl", map[string]any{
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
} else { // return 401
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETConfigDevicesFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETConfigDevicesFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/config-devices.go.tmpl", gin.H{
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/config-devices.go.tmpl", map[string]any{
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
} else { // return 401
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETConfigBootFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETConfigBootFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||
vm_path, err := common.GetInstancePathFromRequest(r)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
config, err := GetInstanceConfig(vm_path, auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
common.HandleNonFatalError(w, fmt.Errorf("error encountered getting instance config: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/config-boot.go.tmpl", gin.H{
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/config-boot.go.tmpl", map[string]any{
|
||||
"config": config,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusUnauthorized)
|
||||
} else { // return 401
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
-16
@@ -1,13 +1,13 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
paas "proxmoxaas-common-lib"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
@@ -45,46 +45,61 @@ type InstanceStatus struct {
|
||||
Status string
|
||||
}
|
||||
|
||||
func HandleGETIndex(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETIndex(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil { // user should be authed, try to return index with population
|
||||
instances, _, err := GetClusterResources(auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
page := gin.H{
|
||||
page := map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "index",
|
||||
"instances": instances,
|
||||
}
|
||||
c.HTML(http.StatusOK, "html/index.html", page)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/index.html", page)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else { // return index without populating
|
||||
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func HandleGETInstancesFragment(c *gin.Context) {
|
||||
auth, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETInstancesFragment(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil { // user should be authed, try to return index with population
|
||||
instances, _, err := GetClusterResources(auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
c.Header("Content-Type", "text/plain")
|
||||
err = common.TMPL.ExecuteTemplate(c.Writer, "html/index-instances.go.tmpl", gin.H{
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/index-instances.go.tmpl", map[string]any{
|
||||
"instances": instances,
|
||||
})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else { // return 401
|
||||
c.Status(http.StatusUnauthorized)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetClusterResources(auth paas.Auth) (map[uint]InstanceCard, map[string]Node, error) {
|
||||
|
||||
+14
-4
@@ -1,11 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
@@ -41,10 +41,11 @@ func GetLoginRealms() ([]Realm, error) {
|
||||
return realms, nil
|
||||
}
|
||||
|
||||
func HandleGETLogin(c *gin.Context) {
|
||||
func HandleGETLogin(w http.ResponseWriter, r *http.Request) {
|
||||
realms, err := GetLoginRealms()
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(c, err)
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
sel := common.Select{
|
||||
@@ -60,9 +61,18 @@ func HandleGETLogin(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "html/login.html", gin.H{
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/login.html", map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "login",
|
||||
"realms": sel,
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
}
|
||||
+21
-6
@@ -1,20 +1,35 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"proxmoxaas-dashboard/app/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func HandleGETSettings(c *gin.Context) {
|
||||
_, err := common.GetAuthFromRequest(c)
|
||||
func HandleGETSettings(w http.ResponseWriter, r *http.Request) {
|
||||
auth, err := common.GetAuthFromRequest(r)
|
||||
if err == nil {
|
||||
c.HTML(http.StatusOK, "html/settings.html", gin.H{
|
||||
_, err := GetUserBasic(auth)
|
||||
if err != nil {
|
||||
common.HandleNonFatalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
body := bytes.Buffer{}
|
||||
err = common.TMPL.ExecuteTemplate(&body, "html/settings.html", map[string]any{
|
||||
"global": common.Global,
|
||||
"page": "settings",
|
||||
})
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(body.Bytes())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user