Exemplo n.º 1
0
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)
	}

}
Exemplo n.º 2
0
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, "/")
	}
}
Exemplo n.º 3
0
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/")
}
Exemplo n.º 4
0
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, "/")
	}

}
Exemplo n.º 5
0
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, "/")
	}
}
Exemplo n.º 6
0
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, "/")
	}
}
Exemplo n.º 7
0
func SignoutHandler(self *vodka.Context) error {
	session := sessions.Default(self)
	session.Delete("user")
	//return self.JSON( 200, "okay")
	return self.Redirect(302, "/")
}