improve auth interface, fix issue in meta

This commit is contained in:
2025-04-02 21:18:29 +00:00
parent bd0387976f
commit 13339cc56d
7 changed files with 26 additions and 20 deletions

View File

@@ -83,9 +83,9 @@ type ResourceChart struct {
}
func HandleGETAccount(c *gin.Context) {
username, token, csrf, err := common.GetAuth(c)
auth, err := common.GetAuth(c)
if err == nil {
account, err := GetUserAccount(username, token, csrf)
account, err := GetUserAccount(auth)
if err != nil {
common.HandleNonFatalError(c, err)
return
@@ -153,16 +153,16 @@ func HandleGETAccount(c *gin.Context) {
}
}
func GetUserAccount(username string, token string, csrf string) (Account, error) {
func GetUserAccount(auth common.Auth) (Account, error) {
account := Account{
Resources: map[string]any{},
}
ctx := common.RequestContext{
Cookies: map[string]string{
"username": username,
"PVEAuthCookie": token,
"CSRFPreventionToken": csrf,
"username": auth.Username,
"PVEAuthCookie": auth.Token,
"CSRFPreventionToken": auth.CSRF,
},
Body: map[string]any{},
}
@@ -179,7 +179,7 @@ func GetUserAccount(username string, token string, csrf string) (Account, error)
if err != nil {
return account, err
} else {
account.Username = username
account.Username = auth.Username
}
ctx.Body = map[string]any{}

View File

@@ -8,7 +8,7 @@ import (
)
func HandleGETConfig(c *gin.Context) {
_, _, _, err := common.GetAuth(c)
_, err := common.GetAuth(c)
if err == nil {
c.HTML(http.StatusOK, "html/config.html", gin.H{
"global": common.Global,

View File

@@ -31,11 +31,11 @@ type Instance struct {
DeleteBtnIcon common.Icon
}
func GetClusterResources(token string, csrf string) (map[uint]Instance, map[string]Node, error) {
func GetClusterResources(auth common.Auth) (map[uint]Instance, map[string]Node, error) {
ctx := common.RequestContext{
Cookies: map[string]string{
"PVEAuthCookie": token,
"CSRFPreventionToken": csrf,
"PVEAuthCookie": auth.Token,
"CSRFPreventionToken": auth.CSRF,
},
Body: map[string]any{},
}
@@ -91,9 +91,9 @@ func GetClusterResources(token string, csrf string) (map[uint]Instance, map[stri
}
func HandleGETIndex(c *gin.Context) {
_, token, csrf, err := common.GetAuth(c)
auth, err := common.GetAuth(c)
if err == nil { // user should be authed, try to return index with population
instances, _, err := GetClusterResources(token, csrf)
instances, _, err := GetClusterResources(auth)
if err != nil {
common.HandleNonFatalError(c, err)
}
@@ -108,9 +108,9 @@ func HandleGETIndex(c *gin.Context) {
}
func HandleGETInstancesFragment(c *gin.Context) {
_, token, csrf, err := common.GetAuth(c)
Auth, err := common.GetAuth(c)
if err == nil { // user should be authed, try to return index with population
instances, _, err := GetClusterResources(token, csrf)
instances, _, err := GetClusterResources(Auth)
if err != nil {
common.HandleNonFatalError(c, err)
}

View File

@@ -8,7 +8,7 @@ import (
)
func HandleGETSettings(c *gin.Context) {
_, _, _, err := common.GetAuth(c)
_, err := common.GetAuth(c)
if err == nil {
c.HTML(http.StatusOK, "html/settings.html", gin.H{
"global": common.Global,