Преглед изворни кода

添加set-password form提交

from remote-desktop пре 4 месеци
родитељ
комит
3f61aa22dc
1 измењених фајлова са 18 додато и 2 уклоњено
  1. 18 2
      src/api/user.go

+ 18 - 2
src/api/user.go

@@ -7,6 +7,8 @@ import (
 	"fmt"
 	"io"
 	"net/http"
+	"net/url"
+	"strings"
 
 	"github.com/gin-gonic/gin"
 )
@@ -41,8 +43,22 @@ func forwardRequestWithJWT(c *gin.Context, targetURL string) (interface{}, error
 
 	req.Header.Set("Authorization", jwtToken)
 
-	// Set content type if it's a POST request
-	if c.Request.Method == "POST" {
+	// Copy the original content type, unless it's the set-password endpoint
+	if strings.Contains(targetURL, "/api/set-password") {
+		req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+		// Parse JSON body and convert to form data
+		if len(bodyBytes) > 0 {
+			var jsonData map[string]interface{}
+			if err := json.Unmarshal(bodyBytes, &jsonData); err != nil {
+				return nil, fmt.Errorf("parse json error: %v", err)
+			}
+			formData := url.Values{}
+			for k, v := range jsonData {
+				formData.Set(k, fmt.Sprintf("%v", v))
+			}
+			req.Body = io.NopCloser(strings.NewReader(formData.Encode()))
+		}
+	} else if c.Request.Method == "POST" {
 		req.Header.Set("Content-Type", "application/json")
 	}