Exemple #1
0
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, "/")
}
Exemple #2
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)
	}

}
Exemple #3
0
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)
}
Exemple #4
0
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, "/")
	}
}
Exemple #5
0
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, "/")

}
Exemple #6
0
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, "/")
	}
}
Exemple #7
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, "/")
	}
}
Exemple #8
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/")
}
Exemple #9
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, "/")
	}
}
Exemple #10
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, "/")
	}
}
Exemple #11
0
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, "/")
	}

}
Exemple #12
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, "/")
	}

}
Exemple #13
0
func NodeDeleteHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64(":nid")
	models.DelNode(nid)
	return self.Redirect(302, "/")
}
Exemple #14
0
func TopicDeleteHandler(self *vodka.Context) error {
	tid, _ := self.ParamInt64(":tid")
	models.DelTopic(tid)
	return self.Redirect(302, "/")
}
Exemple #15
0
func SignoutHandler(self *vodka.Context) error {
	session := sessions.Default(self)
	session.Delete("user")
	//return self.JSON( 200, "okay")
	return self.Redirect(302, "/")
}
Exemple #16
0
func DeleteReplyHandler(self *vodka.Context) error {
	rid, _ := self.ParamInt64(":rid")
	models.DelReply(rid)
	return self.Redirect(302, "/")
}