Parcourir la source

move redirec to crmpixel ,as they both emphasis on auth cookies.

master
Patrick Peng Sun il y a 8 ans
Parent
révision
9de2757c44
2 fichiers modifiés avec 30 ajouts et 29 suppressions
  1. +30
    -0
      crmpixel.go
  2. +0
    -29
      main.go

+ 30
- 0
crmpixel.go Voir le fichier

@@ -7,6 +7,7 @@ import (
"fmt"
"math/rand"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@@ -140,3 +141,32 @@ func crmpixelLead(id string) (info crmdLead, err error) {
}
return
}

//for user's initial registration, especially for wechat users
//they visit a url that is specifically designed for them to
//auth and input their profile data.
//the url's query string will contains a token and a signature
//so that it's verified, by single get request, to allow people to
//enter their details into the CRM system.
//
//this handler, check's the query sting ,set an auth cookie to the client
//and serve angular app, through an URL "/profile/edit"
//or if the user has already been registered,
//redirect user to a URL "/pages/dashboard"
//
func setTrackingCookieAndRecirect(w http.ResponseWriter, r *http.Request) {

cookie := crmpixelCookie(r)
http.SetCookie(w, &cookie)

rq := r.URL.RawQuery
m, _ := url.ParseQuery(rq)

url, ok := m["url"]
if ok {
http.Redirect(w, r, url[0], 307) //302 temp redirect
return
}
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "Not Found URL")
}

+ 0
- 29
main.go Voir le fichier

@@ -176,32 +176,3 @@ func mpDomainAuthSecret(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "6JqVkftKr39GMakA")
//由于需要什么ICP备案,这个功能不能使用
}

//for user's initial registration, especially for wechat users
//they visit a url that is specifically designed for them to
//auth and input their profile data.
//the url's query string will contains a token and a signature
//so that it's verified, by single get request, to allow people to
//enter their details into the CRM system.
//
//this handler, check's the query sting ,set an auth cookie to the client
//and serve angular app, through an URL "/profile/edit"
//or if the user has already been registered,
//redirect user to a URL "/pages/dashboard"
//
func setTrackingCookieAndRecirect(w http.ResponseWriter, r *http.Request) {

cookie := crmpixelCookie(r)
http.SetCookie(w, &cookie)

rq := r.URL.RawQuery
m, _ := url.ParseQuery(rq)

url, ok := m["url"]
if ok {
http.Redirect(w, r, url[0], 307) //302 temp redirect
return
}
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "Not Found URL")
}

Chargement…
Annuler
Enregistrer