Exemplo n.º 1
0
func RecordVisit() martini.Handler {
	return func(s sessions.Session, r *http.Request) {
		visit := new(model.Visit)
		visit.SessionId = s.GetId()
		user := s.Get("SignedUser")
		var id int
		if user != nil {
			if reflect.TypeOf(user).Kind() == reflect.Struct {
				id = user.(model.User).Id
			} else {
				id = user.(*model.User).Id
			}
		}
		visit.User = model.User{Id: id}
		visit.Ip = GetRemoteIp(r)
		if visit.ExistVisit() {
			visit.Update()
		} else {
			visit.Insert()
		}
	}
}
Exemplo n.º 2
0
func DashboardHandler(ctx *middleware.Context) {
	visit := new(model.Visit)
	visit.SetPageActive(true)
	visit.SetPageSize(10)
	pageNo := ParseInt(ctx.R.FormValue("page"))
	visit.SetPageNo(pageNo)
	visit.AddSortProperty("create_date", "desc")
	visitList, total, err := visit.SearchByPage()
	PanicIf(err)

	visit.SetTotalRecord(total)
	visit.Result = visitList
	ctx.Set("Visit", visit)
	ctx.HTML(200, "admin/dashboard", ctx)
}