本文整理汇总了Golang中github.com/fuxiaohei/GoBlog/GoInk.Context.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Redirect方法的具体用法?Golang Context.Redirect怎么用?Golang Context.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/fuxiaohei/GoBlog/GoInk.Context
的用法示例。
在下文中一共展示了Context.Redirect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Login
func Login(context *GoInk.Context) {
if context.Method == "POST" {
data := context.Input()
user := model.GetUserByName(data["user"])
if user == nil {
Json(context, false).End()
return
}
if !user.CheckPassword(data["password"]) {
Json(context, false).End()
return
}
exp := 3600 * 24 * 3
expStr := strconv.Itoa(exp)
s := model.CreateToken(user, context, int64(exp))
context.Cookie("token-user", strconv.Itoa(s.UserId), expStr)
context.Cookie("token-value", s.Value, expStr)
Json(context, true).End()
return
}
if context.Cookie("token-value") != "" {
context.Redirect("/admin/")
return
}
context.Render("home/login", nil)
}
示例2: Auth
func Auth(context *GoInk.Context) {
tokenValue := context.Cookie("token-value")
token := model.GetTokenByValue(tokenValue)
if token == nil {
context.Redirect("/logout/")
context.End()
return
}
if !token.IsValid() {
context.Redirect("/logout/")
context.End()
return
}
}
示例3: TopPage
func TopPage(context *GoInk.Context) {
slug := context.Param("slug")
page := model.GetContentBySlug(slug)
if page == nil {
context.Redirect("/")
return
}
if page.IsLinked && page.Type == "page" {
context.Layout("home")
context.Render("home/page", map[string]interface{}{
"Title": page.Title,
"Page": page,
})
page.Hits++
return
}
context.Redirect("/")
}
示例4: Page
func Page(context *GoInk.Context) {
id, _ := strconv.Atoi(context.Param("id"))
slug := context.Param("slug")
article := model.GetContentById(id)
if article == nil {
context.Redirect("/")
return
}
if article.Slug != slug || article.Type != "page" {
context.Redirect("/")
return
}
article.Hits++
context.Layout("home")
context.Render("home/page", map[string]interface{}{
"Title": article.Title,
"Page": article,
//"CommentHtml": Comments(context, article),
})
}
示例5: PageEdit
func PageEdit(context *GoInk.Context) {
id, _ := strconv.Atoi(context.Param("id"))
c := model.GetContentById(id)
if c == nil {
context.Redirect("/admin/pages/")
return
}
if context.Method == "DELETE" {
model.RemoveContent(c)
Json(context, true).End()
return
}
if context.Method == "POST" {
data := context.Input()
if !c.ChangeSlug(data["slug"]) {
Json(context, false).Set("msg", "固定链接重复").End()
return
}
c.Title = data["title"]
c.Text = data["content"]
//c.Tags = strings.Split(strings.Replace(data["tag"], ",", ",", -1), ",")
c.IsComment = data["comment"] == "1"
c.IsLinked = data["link"] == "1"
//c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
//c.Template = "blog.html"
c.Status = data["status"]
//c.Format = "markdown"
model.SaveContent(c)
Json(context, true).Set("content", c).End()
//c.Type = "article"
return
}
context.Layout("admin")
context.Render("admin/edit_page", map[string]interface{}{
"Title": "编辑文章",
"Page": c,
})
}
示例6: Logout
func Logout(context *GoInk.Context) {
context.Cookie("token-user", "", "-3600")
context.Cookie("token-value", "", "-3600")
context.Redirect("/login/")
}