func home_index(ctx *goku.HttpContext) goku.ActionResulter { u, ok := ctx.Data["user"] if !ok || u == nil { return ctx.Redirect("/discover") } user := u.(*models.User) if user.FriendCount+user.FtopicCount < 1 { return home_guideForNew(ctx) } ot := ctx.Get("o") if ot == "" { ot = "hot" } ctx.ViewData["Order"] = ot links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20) ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE // 最新链接的未读提醒 if ot == "hot" { newestUnreadCount, _ := models.NewestLinkUnread_Friends(user.Id, user.LastReadFriendLinkId) ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(user.Id, newestUnreadCount) } else if ot == "time" && links != nil && len(links) > 0 { models.NewestLinkUnread_UpdateForUser(user.Id, links[0].Id) } return ctx.View(nil) }
/** * 提交一个链接并保存到数据库 */ func link_submit(ctx *goku.HttpContext) goku.ActionResulter { f := forms.CreateLinkSubmitForm() f.FillByRequest(ctx.Request) var resubmit bool if ctx.Get("resubmit") == "true" { resubmit = true } user := ctx.Data["user"].(*models.User) success, linkId, errorMsgs, _ := models.Link_SaveForm(f, user.Id, resubmit) if success { go addLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本 TODO: return ctx.Redirect(fmt.Sprintf("/link/%d", linkId)) } else if linkId > 0 { return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId)) } else { ctx.ViewData["Errors"] = errorMsgs ctx.ViewData["Values"] = f.Values() } return ctx.View(nil) }
func loginThirdPartyUser(u *models.ThirdPartyUser, ctx *goku.HttpContext) goku.ActionResulter { user := u.User() userId, email, expireInSeconds := user.Id, user.Email, 24*3600 /*if !u.TokenExpireTime.IsZero() { utcNow := time.Now().UTC() expireInSeconds = int(u.TokenExpireTime.Sub(utcNow) / time.Second) }*/ setCookieForOtherPlatformUser(userId, email, expireInSeconds, ctx) return ctx.Redirect("/") }
func (tf *RequireLoginFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) { if u, ok := ctx.Data["user"]; !ok || u == nil { if ctx.IsAjax() { ar = ctx.Json(map[string]interface{}{ "success": false, "needLogin": true, "errors": "请先登陆", }) } else { ar = ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI)) } } return }
func home_index(ctx *goku.HttpContext) goku.ActionResulter { u, ok := ctx.Data["user"] if !ok || u == nil { return ctx.Redirect("/discover") } user := u.(*models.User) ot := ctx.Get("o") if ot == "" { ot = "hot" } ctx.ViewData["Order"] = ot links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20) ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE return ctx.View(nil) }
/** * 提交一个链接并保存到数据库 */ func link_submit(ctx *goku.HttpContext) goku.ActionResulter { f := forms.CreateLinkSubmitForm() f.FillByRequest(ctx.Request) success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id) if success { return ctx.Redirect(fmt.Sprintf("/link/%d", linkId)) } else { ctx.ViewData["Errors"] = errorMsgs ctx.ViewData["Values"] = f.Values() } return ctx.View(nil) }
/** * 提交一个链接并保存到数据库 */ func link_submit(ctx *goku.HttpContext) goku.ActionResulter { f := forms.CreateLinkSubmitForm() f.FillByRequest(ctx.Request) var resubmit bool if ctx.Get("resubmit") == "true" { resubmit = true } success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id, resubmit) if success { return ctx.Redirect(fmt.Sprintf("/link/%d", linkId)) } else if linkId > 0 { return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId)) } else { ctx.ViewData["Errors"] = errorMsgs ctx.ViewData["Values"] = f.Values() } return ctx.View(nil) }
func RequireLogin(ctx *goku.HttpContext) goku.ActionResulter { if u, ok := ctx.Data["user"]; !ok || u == nil { return ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI)) } return nil }
func (p OAuth2Provider) Login(ctx *goku.HttpContext) (actionResult goku.ActionResulter, err error) { url := p.Config.AuthCodeURL("") actionResult = ctx.Redirect(url) return }