Procházet zdrojové kódy

get query params from url

abhishek9686 před 1 rokem
rodič
revize
4d81d8ec1f
2 změnil soubory, kde provedl 10 přidání a 3 odebrání
  1. 4 2
      controllers/user.go
  2. 6 1
      logic/notification.go

+ 4 - 2
controllers/user.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"net/url"
 
 	"github.com/gorilla/mux"
 	"github.com/gorilla/websocket"
@@ -1143,8 +1144,9 @@ func userInviteSignUp(w http.ResponseWriter, r *http.Request) {
 //	Responses:
 //		200: ReturnSuccessResponse
 func userInviteVerify(w http.ResponseWriter, r *http.Request) {
-	email := r.URL.Query().Get("email")
-	code := r.URL.Query().Get("code")
+	params, _ := url.ParseQuery(r.URL.String())
+	email := params.Get("email")
+	code := params.Get("code")
 	logger.Log(0, "EMAIL", email, "CODE", code)
 	err := logic.ValidateAndApproveUserInvite(email, code)
 	if err != nil {

+ 6 - 1
logic/notification.go

@@ -3,6 +3,7 @@ package logic
 import (
 	"crypto/tls"
 	"fmt"
+	"net/url"
 
 	gomail "gopkg.in/mail.v2"
 
@@ -30,8 +31,12 @@ func SendInviteEmail(invite models.UserInvite) error {
 	m.SetHeader("Subject", "Netmaker Invite")
 
 	// Set E-Mail body. You can set plain text or html with text/html
-	m.SetBody("text/html", "Click Here to Signup! <a>"+fmt.Sprintf("https://api.%s/api/v1/users/invite?email=%s&code=%v",
+	u, err := url.Parse(fmt.Sprintf("https://api.%s/api/v1/users/invite?email=%s&code=%s",
 		servercfg.GetServer(), invite.Email, invite.InviteCode))
+	if err != nil {
+		return err
+	}
+	m.SetBody("text/html", "Click Here to Signup! <a>"+u.String())
 
 	// Settings for SMTP server
 	d := gomail.NewDialer(smtpHost, smtpPort, senderEmail, senderPassword)