|
|
|
@@ -45,7 +45,9 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) { |
|
|
|
return |
|
|
|
} |
|
|
|
session.RenewIfExpireSoon() |
|
|
|
session.SetRemote(r) //make sure they are using latest remote |
|
|
|
session.SetRemote(r) //make sure they are using latest remote |
|
|
|
session.Add("mid", apiV1GetMachineId(r)) //set machine id |
|
|
|
apiV1AddTrackingCookie(w, r, &session) // add tracking cookie to client |
|
|
|
|
|
|
|
//we have a session now, either guest or valid user |
|
|
|
//search through handler |
|
|
|
@@ -66,7 +68,7 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) { |
|
|
|
apiV1DumpRequest(w, r, &session) |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1InitSessionByBrowserId(w http.ResponseWriter, r *http.Request, session *loan.Session) { |
|
|
|
func apiV1GetMachineId(r *http.Request) string { |
|
|
|
var mid string |
|
|
|
inCookie, e := r.Cookie("mid") |
|
|
|
if e == nil { |
|
|
|
@@ -74,9 +76,14 @@ func apiV1InitSessionByBrowserId(w http.ResponseWriter, r *http.Request, session |
|
|
|
} else { |
|
|
|
mid = strconv.Itoa(int(time.Now().Unix())) + "-" + gofakeit.UUID() |
|
|
|
} |
|
|
|
return mid |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1InitSessionByBrowserId(w http.ResponseWriter, r *http.Request, session *loan.Session) { |
|
|
|
mid := apiV1GetMachineId(r) |
|
|
|
|
|
|
|
var sid string |
|
|
|
inCookie, e = r.Cookie("session") |
|
|
|
inCookie, e := r.Cookie("session") |
|
|
|
if e == nil { |
|
|
|
sid = inCookie.Value |
|
|
|
if sid != "" { |
|
|
|
@@ -91,12 +98,15 @@ func apiV1InitSessionByBrowserId(w http.ResponseWriter, r *http.Request, session |
|
|
|
session.Add("mid", mid) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1AddTrackingCookie(w http.ResponseWriter, r *http.Request, session *loan.Session) { |
|
|
|
//add tracking cookie |
|
|
|
expiration := time.Now().Add(365 * 24 * time.Hour) |
|
|
|
cookie := http.Cookie{Name: "session", Value: session.Id, Expires: expiration} |
|
|
|
http.SetCookie(w, &cookie) |
|
|
|
|
|
|
|
mid := apiV1GetMachineId(r) |
|
|
|
cookie = http.Cookie{Name: "mid", Value: mid, Expires: expiration} |
|
|
|
http.SetCookie(w, &cookie) |
|
|
|
|