Quellcode durchsuchen

when check cookie we do not retrieve lead record.

master
Patrick Peng Sun vor 8 Jahren
Ursprung
Commit
82f93c0011
2 geänderte Dateien mit 23 neuen und 13 gelöschten Zeilen
  1. +22
    -12
      crmpixel.go
  2. +1
    -1
      crmpixel_test.go

+ 22
- 12
crmpixel.go Datei anzeigen

"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
) )


func crmpixel(w http.ResponseWriter, r *http.Request) { func crmpixel(w http.ResponseWriter, r *http.Request) {


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


//send out pixel 1x1 transparent png file //send out pixel 1x1 transparent png file
} }
} }


func crmpixelCookie(r *http.Request) (ret http.Cookie, info crmdLead) {
func crmpixelCookie(r *http.Request) (ret http.Cookie) {
cookie, leadok := r.Cookie("biukop_cl") //crm lead cookie, leadok := r.Cookie("biukop_cl") //crm lead


if leadok != nil { if leadok != nil {
ret, info = createNewCookie(r)
ret, _ = createNewCookie(r)
return return
} }


valid, info := isValidCookieBiukopCL(cookie.Value)
valid := isValidCookieBiukopCL(cookie.Value)
if !valid { if !valid {
ret, info = createNewCookie(r)
ret, _ = createNewCookie(r)
return return
} }




func crmCreateNewAnonymousLeadByHTTPRequest(r *http.Request) (info crmdLead) { func crmCreateNewAnonymousLeadByHTTPRequest(r *http.Request) (info crmdLead) {
info.FirstName = "Anonymous" info.FirstName = "Anonymous"
info.LastName = "User"
info.LastName = "User " + r.RemoteAddr
info.Password = "Password" info.Password = "Password"
info.Status = "Anonymous" info.Status = "Anonymous"
info.Description = "Anonymous from " + r.RemoteAddr
info.Description = "Anonymous user from " + r.RemoteAddr
info.ForceDuplicate = true info.ForceDuplicate = true
b, err := json.Marshal(info) b, err := json.Marshal(info)
if err != nil { if err != nil {
return return
} }


func isValidCookieBiukopCL(cookieValue string) (valid bool, info crmdLead) {
func isValidCookieBiukopCL(cookieValue string) (valid bool) {
valid = false valid = false


//correctly split string //correctly split string
return return
} }


//find lead data
info, err := crmpixelLead(id)
ts, err := strconv.Atoi(timestamp)
if err != nil { if err != nil {
return return
} }

if timestampOldThan(int32(ts), 86400) { //older than 1 day
//find lead data
_, err := crmpixelLead(id)
if err != nil {
return
}
}
valid = true valid = true
return return
} }


func crmpixelLead(id string) (info crmdLead, err error) { func crmpixelLead(id string) (info crmdLead, err error) {
entity, err := crmGetEntity("Lead", id) entity, err := crmGetEntity("Lead", id)
if err != nil {
return
}

info, ok := entity.(crmdLead) info, ok := entity.(crmdLead)
if !ok { if !ok {
err = errors.New("search lead, return a bad entity type") err = errors.New("search lead, return a bad entity type")

+ 1
- 1
crmpixel_test.go Datei anzeigen

// Extract the dropped cookie from the request. // Extract the dropped cookie from the request.
cookie, err := request.Cookie("biukop_cl") cookie, err := request.Cookie("biukop_cl")


valid, _ := isValidCookieBiukopCL(cookie.Value)
valid := isValidCookieBiukopCL(cookie.Value)
return err == nil && valid return err == nil && valid
} }



Laden…
Abbrechen
Speichern