Kaynağa Gözat

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

master
Patrick Peng Sun 8 yıl önce
ebeveyn
işleme
9de2757c44
2 değiştirilmiş dosya ile 30 ekleme ve 29 silme
  1. +30
    -0
      crmpixel.go
  2. +0
    -29
      main.go

+ 30
- 0
crmpixel.go Dosyayı Görüntüle

"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"strings" "strings"
"time" "time"
} }
return 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 Dosyayı Görüntüle

fmt.Fprintf(w, "6JqVkftKr39GMakA") fmt.Fprintf(w, "6JqVkftKr39GMakA")
//由于需要什么ICP备案,这个功能不能使用 //由于需要什么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")
}

Yükleniyor…
İptal
Kaydet