Exemple #1
0
//更新帖子
func (self *TopicHandler) Put() {

	if hash := self.GetString("hash"); hash != "" {

		if rsa_decrypt_content, err := helper.ReceivingPackets(true, hash, "PUT", self.Ctx.Input.RequestBody, aesPublicKey, rsaPublicKey, rsaPrivateKey); err == nil {

			tid, _ := self.GetInt(":objectId")
			tp := new(model.Topic)
			json.Unmarshal(rsa_decrypt_content, &tp)

			if _, err := model.PutTopic(tid, tp); err != nil {
				self.Data["json"] = "Update failed!"
			} else {
				self.Data["json"] = "Update success!"
			}
			self.ServeJson()
		} else {

			fmt.Println("401 Unauthorized!")
			self.Abort("401")
		}
	} else {

		fmt.Println("401 Unauthorized!")
		self.Abort("401")
	}
}
Exemple #2
0
//创建帖子
func (self *TopicHandler) Post() {

	if hash := self.GetString("hash"); hash != "" {
		//(decrypt bool, hash string, status string, content []byte, aesPublicKey string, rsaPublicKey []byte, rsaPrivateKey []byte)
		if rsa_decrypt_content, err := helper.ReceivingPackets(true, hash, "POST", self.Ctx.Input.RequestBody, aesPublicKey, rsaPublicKey, rsaPrivateKey); err == nil {
			tp := new(model.Topic)
			json.Unmarshal(rsa_decrypt_content, &tp)
			if tid, err := model.PostTopic(tp); err != nil {

				self.Data["json"] = "Post failed!"
			} else {
				self.Data["json"] = `{"TopicId:"` + strconv.Itoa(int(tid)) + `}`
			}

			self.ServeJson()
		} else {

			fmt.Println("401 Unauthorized!")
			self.Abort("401")
		}
	} else {

		fmt.Println("401 Unauthorized!")
		self.Abort("401")
	}
}
Exemple #3
0
//删除帖子
func (self *TopicHandler) Delete() {
	if hash := self.GetString("hash"); hash != "" {

		if rsa_decrypt_content, err := helper.ReceivingPackets(true, hash, "DELETE", self.Ctx.Input.RequestBody, aesPublicKey, rsaPublicKey, rsaPrivateKey); err == nil {

			tid, _ := self.GetInt(":objectId")
			var tp *model.Topic
			json.Unmarshal(rsa_decrypt_content, &tp)
			if tid == tp.Id && tid > 0 {
				if e := model.DelTopic(tid, 1, -100000); e != nil {
					self.Data["json"] = "Delete failed!"

				} else {

					self.Data["json"] = "Delete success!"
				}
				//self.ServeJson()
				self.Ctx.WriteString(self.Data["json"].(string))

			} else {

				fmt.Println("401 Unauthorized!")
				self.Abort("401")
			}

		} else {

			fmt.Println("401 Unauthorized!")
			self.Abort("401")
		}
	} else {

		fmt.Println("401 Unauthorized!")
		self.Abort("401")
	}
}