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


Golang Context.Redirect方法代码示例

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


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

示例1: NewCategoryPostHandler

func NewCategoryPostHandler(self *vodka.Context) error {

	t := self.FormEscape("title")
	c := self.FormEscape("content")
	if t != "" && c != "" {
		models.AddCategory(t, c)
	}
	return self.Redirect(302, "/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:9,代码来源:NewCategory.go

示例2: SigninGetHandler

func SigninGetHandler(self *vodka.Context) error {

	session := sessions.Default(self)

	val := session.Get("user")
	if val != nil {
		return self.Redirect(302, "/")
	} else {
		return self.Render(http.StatusOK, "signin.html", nil)
	}

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:12,代码来源:SigninHandler.go

示例3: SignupPostHandler

func SignupPostHandler(self *vodka.Context) error {

	data := make(map[string]interface{})

	username := self.FormEscape("username")
	password := self.FormEscape("password")
	usererr := helper.CheckUsername(username)

	if usererr == false {
		e := errors.New("Username error, Please to again")
		data["UsernameErr"] = e.Error()
		return e
	}

	passerr := helper.CheckPassword(password)
	if passerr == false {
		e := errors.New("Password error, Please to again")
		data["PasswordErr"] = e.Error()
		return e
	}

	pwd := helper.EncryptHash(password, nil)

	//now := torgo.Date(time.Now(), "Y-m-d H:i:s")

	userInfo := models.CheckUserByNickname(username)

	fmt.Println(userInfo.Nickname)

	//  检查该用户是否已经被注册
	if userInfo.Nickname == "" {

		//注册用户
		regErr := models.AddUser(username+"@insion.co", username, "", pwd, 1)
		fmt.Println("reg:s")
		fmt.Println(regErr)
		fmt.Println("reg:e ")
		//注册成功设置session
		//	self.SetSession("userid", userInfo.Id)
		//	self.SetSession("username", userInfo.Nickname)
		//	self.SetSession("userrole", userInfo.Role)
		//	self.SetSession("useremail", userInfo.Email)
		return self.Redirect(302, "/signin/")

	} else {
		e := errors.New("User already exists")
		data["UsernameErr"] = e.Error()
		return e
	}
	return self.Render(http.StatusOK, "signup.html", data)
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:51,代码来源:SignupHandler.go

示例4: ModifyCatPostHandler

func ModifyCatPostHandler(self *vodka.Context) error {

	cid, _ := self.ParamInt64("categoryid")

	cat_title := self.ParamEscape("title")
	cat_content := self.ParamEscape("content")
	if cid != 0 && cat_title != "" && cat_content != "" {
		var cat models.Category
		cat.Id = int64(cid)
		cat.Title = cat_title
		cat.Content = cat_content
		cat.Created = time.Now()
		models.UpdateCategory(cat.Id, cat)
		return self.Redirect(302, fmt.Sprintf("/category/%v/", cid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:18,代码来源:ModifyCategory.go

示例5: ViewHandler

func ViewHandler(self *vodka.Context) error {

	data := make(map[string]interface{})
	tid, _ := self.ParamInt64(":tid")
	tid_handler := models.GetTopic(tid)

	if tid_handler.Id > 0 {

		tid_handler.Views = tid_handler.Views + 1
		models.UpdateTopic(tid, tid_handler)

		data["article"] = tid_handler
		data["replys"] = models.GetReplyByPid(tid, 0, 0, "id")

		tps := models.GetAllTopicByCid(tid_handler.Cid, 0, 0, 0, "asc")

		if tps != nil && tid != 0 {

			for i, v := range tps {

				if v.Id == tid {
					prev := i - 1
					next := i + 1

					for i, v := range tps {
						if prev == i {
							data["previd"] = v.Id
							data["prev"] = v.Title
						}
						if next == i {
							data["nextid"] = v.Id
							data["next"] = v.Title
						}
					}
				}
			}
		}

		return self.Render(http.StatusOK, "view.html", data)
	}

	return self.Redirect(302, "/")

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:44,代码来源:ViewHandler.go

示例6: ModifyNodePostHandler

func ModifyNodePostHandler(self *vodka.Context) error {

	cid, _ := self.ParamInt64("categoryid")
	nid, _ := self.ParamInt64("nodeid")

	nd_title := self.FormEscape("title")
	nd_content := self.FormEscape("content")
	if cid != 0 && nid != 0 && nd_title != "" && nd_content != "" {
		nd := new(models.Node)
		nd.Id = int64(nid)
		nd.Pid = int64(cid)
		nd.Title = nd_title
		nd.Content = nd_content
		nd.Created = time.Now()
		models.UpdateNode(nd.Id, nd)
		return self.Redirect(302, fmt.Sprintf("/node/%v/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:20,代码来源:ModifyNode.go

示例7: NodeEditPostHandler

func NodeEditPostHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64(":nid")
	cid, _ := self.ParamInt64("categoryid")

	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id

	nid_title := self.FormEscape("title")
	nid_content := self.FormEscape("content")
	if nid_title != "" && nid_content != "" {
		models.EditNode(nid, cid, uid, nid_title, nid_content)
		return self.Redirect(302, fmt.Sprintf("/node/%v/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:21,代码来源:EditNode.go

示例8: SigninPostHandler

func SigninPostHandler(self *vodka.Context) error {
	username := self.FormEscape("username")
	password := self.FormEscape("password")

	if username != "" && password != "" {

		if userInfo := models.GetUserByNickname(username); userInfo.Password != "" {

			if helper.ValidateHash(userInfo.Password, password) {
				session := sessions.Default(self)
				session.Set("user", userInfo)

				if e := session.Save(); e == nil {
					return self.Redirect(302, "/")
				}

			}
		}
	}
	return self.Redirect(302, "/signin/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:21,代码来源:SigninHandler.go

示例9: TopicEditPostHandler

func TopicEditPostHandler(self *vodka.Context) error {
	tid, _ := self.ParamInt64(":tid")
	nid, _ := self.ParamInt64("nodeid")
	cid := models.GetNode(nid).Pid

	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id
	tid_title := self.FormEscape("title")
	tid_content := self.FormEscape("content")

	if tid_title != "" && tid_content != "" {
		models.EditTopic(tid, nid, cid, uid, tid_title, tid_content)
		return self.Redirect(302, fmt.Sprintf("/view/%v/", tid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:22,代码来源:EditTopic.go

示例10: NewTopicPostHandler

func NewTopicPostHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64("nodeid")
	cid := models.GetNode(nid).Pid
	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id
	author := user.Nickname

	tid_title := self.FormEscape("title")
	tid_content := self.FormEscape("content")

	if tid_title != "" && tid_content != "" {
		models.AddTopic(tid_title, tid_content, cid, nid, uid, author)
		return self.Redirect(302, fmt.Sprintf("/node/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:22,代码来源:NewTopic.go

示例11: NodeHandler

func NodeHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	page, _ := self.ParamInt64("page")
	nid, _ := self.ParamInt64(":nid")

	nid_handler := models.GetNode(nid)
	nid_handler.Views = nid_handler.Views + 1
	models.UpdateNode(nid, nid_handler)

	limit := 25
	rcs := len(models.GetAllTopicByNid(nid, 0, 0, 0, "hotness"))
	pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)
	data["pagesbar"] = helper.Pagesbar("", rcs, pages, pageout, beginnum, endnum, 1)
	data["nodeid"] = nid
	data["topics_hotness"] = models.GetAllTopicByNid(nid, offset, limit, 0, "hotness")
	data["topics_latest"] = models.GetAllTopicByNid(nid, offset, limit, 0, "id")

	if nid != 0 {
		return self.Render(http.StatusOK, "node.html", data)
	} else {
		return self.Redirect(302, "/")
	}

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:24,代码来源:NodeHandler.go

示例12: NewReplyPostHandler

func NewReplyPostHandler(self *vodka.Context) error {
	tid := self.FormInt64("comment_parent")

	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}

	sess_userid := user.Id

	gmt, _ := self.Request().Cookie("gmt")

	if gmt != nil {

		if _, err := url.QueryUnescape(gmt.Value); err == nil {

			author := self.FormEscape("author")
			email := self.FormEscape("email")
			website := self.FormEscape("website")
			rc := self.FormEscape("comment")

			if author != "" && email != "" && tid != 0 && rc != "" {
				if err := models.AddReply(tid, sess_userid, rc, author, email, website); err != nil {
					return err
				}
				return self.Redirect(302, fmt.Sprintf("/view/", tid))
			} else {
				return self.Redirect(302, "/")
			}
		} else {
			return self.Redirect(302, "/")
		}

	} else {
		return self.Redirect(302, "/")
	}

}
开发者ID:xqbumu,项目名称:zenpress,代码行数:40,代码来源:NewReply.go

示例13: NodeDeleteHandler

func NodeDeleteHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64(":nid")
	models.DelNode(nid)
	return self.Redirect(302, "/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:5,代码来源:DelNode.go

示例14: TopicDeleteHandler

func TopicDeleteHandler(self *vodka.Context) error {
	tid, _ := self.ParamInt64(":tid")
	models.DelTopic(tid)
	return self.Redirect(302, "/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:5,代码来源:DelTopic.go

示例15: SignoutHandler

func SignoutHandler(self *vodka.Context) error {
	session := sessions.Default(self)
	session.Delete("user")
	//return self.JSON( 200, "okay")
	return self.Redirect(302, "/")
}
开发者ID:xqbumu,项目名称:zenpress,代码行数:6,代码来源:SignoutHandler.go


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