当前位置: 首页>>代码示例>>Golang>>正文


Golang HttpContext.Redirect方法代码示例

本文整理汇总了Golang中github.com/QLeelulu/goku.HttpContext.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang HttpContext.Redirect方法的具体用法?Golang HttpContext.Redirect怎么用?Golang HttpContext.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/QLeelulu/goku.HttpContext的用法示例。


在下文中一共展示了HttpContext.Redirect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: home_index

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)
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:28,代码来源:home.go

示例2: link_submit

/**
 * 提交一个链接并保存到数据库
 */
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)

}
开发者ID:hippasus,项目名称:ohlala,代码行数:28,代码来源:link.go

示例3: loginThirdPartyUser

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("/")
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:11,代码来源:user_reg_login.go

示例4: OnActionExecuting

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
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:14,代码来源:require_login.go

示例5: home_index

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)
}
开发者ID:t7er,项目名称:ohlala,代码行数:16,代码来源:home.go

示例6: link_submit

/**
 * 提交一个链接并保存到数据库
 */
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)

}
开发者ID:arowser,项目名称:ohlala,代码行数:19,代码来源:link.go

示例7: link_submit

/**
 * 提交一个链接并保存到数据库
 */
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)

}
开发者ID:kicool,项目名称:ohlala,代码行数:26,代码来源:link.go

示例8: RequireLogin

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
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:6,代码来源:base.go

示例9: Login

func (p OAuth2Provider) Login(ctx *goku.HttpContext) (actionResult goku.ActionResulter, err error) {
	url := p.Config.AuthCodeURL("")
	actionResult = ctx.Redirect(url)
	return
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:5,代码来源:third_party_user.go


注:本文中的github.com/QLeelulu/goku.HttpContext.Redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。