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() } } }
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) }