Просмотр исходного кода

when check cookie we do not retrieve lead record.

master
Patrick Peng Sun 8 лет назад
Родитель
Сommit
82f93c0011
2 измененных файлов: 23 добавлений и 13 удалений
  1. +22
    -12
      crmpixel.go
  2. +1
    -1
      crmpixel_test.go

+ 22
- 12
crmpixel.go Просмотреть файл

@@ -5,9 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
)
@@ -20,8 +20,7 @@ func crmpixelImage() (pixel []byte, err error) {

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

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

//send out pixel 1x1 transparent png file
@@ -33,17 +32,17 @@ func crmpixel(w http.ResponseWriter, r *http.Request) {
}
}

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

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

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

@@ -64,10 +63,10 @@ func createNewCookie(r *http.Request) (ret http.Cookie, info crmdLead) {

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

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

//correctly split string
@@ -97,11 +96,18 @@ func isValidCookieBiukopCL(cookieValue string) (valid bool, info crmdLead) {
return
}

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

if timestampOldThan(int32(ts), 86400) { //older than 1 day
//find lead data
_, err := crmpixelLead(id)
if err != nil {
return
}
}
valid = true
return
}
@@ -124,6 +130,10 @@ func buildBiukopCLValue(id string) (ret string) {

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

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

+ 1
- 1
crmpixel_test.go Просмотреть файл

@@ -32,7 +32,7 @@ func checkRecorderCookieBiukopCL(v []string) bool {
// Extract the dropped cookie from the request.
cookie, err := request.Cookie("biukop_cl")

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


Загрузка…
Отмена
Сохранить