Пример #1
0
func (c App) updateVisitor(v *user.Visitor) error {

	pr, err := analytics.ParsePageRequest(c.Request.Request)
	checkERROR(err)
	// revel.WARN.Printf("PageReq: \n%+v\n", pr)

	// check ip addresses and do something
	ip := "missing"
	if pr.XRealIp != "" {
		ip = pr.XRealIp
	}

	if ip != v.VisitorIp {
		revel.INFO.Println("visitor connecting from new ip")

		v.VisitorIp = ip

		err = user.UpdateVisitor(c.Txn, v)
		checkERROR(err)
	}

	c.RenderArgs["visitor"] = v

	return nil
}
Пример #2
0
// helper functions
func (c App) addNewVisitor() (*user.Visitor, error) {

	pr, err := analytics.ParsePageRequest(c.Request.Request)
	checkERROR(err)
	// revel.WARN.Printf("PageReq: \n%+v\n", pr)

	vid, err := user.GenerateNewVisitorId(c.Txn)
	checkERROR(err)

	ip := "missing"
	if pr.XRealIp != "" {
		ip = pr.XRealIp
	}

	err = user.AddVisitor(c.Txn, vid, ip)
	checkERROR(err)

	v := &user.Visitor{
		VisitorId: vid,
		VisitorIp: ip,
	}

	c.Session["v"] = fmt.Sprint(v.VisitorId)
	c.RenderArgs["visitor"] = v

	return v, nil
}