Example #1
0
func AddComment(c *gin.Context) {

	var prof_in *Profile
	status := http.StatusOK
	if auth.IsAuthenticated(c) {

		conn := store.New(c)
		var comment Comment
		c.BindJSON(&comment)

		prof_id, _ := strconv.ParseInt(comment.Prof_Id, 10, 64)
		det_id, _ := strconv.ParseInt(comment.Det_Id, 10, 64)
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		prof_in = &Profile{Id: prof_id, Parent: det_key}
		conn.Get(prof_in)

		comment.Id = uuid.NewV4().String()
		comment.Time = time.Now().Format("2006-01-02 15-04-05")
		comment.Author = auth.GetUser(c).Name
		prof_in.Comments = append(prof_in.Comments, comment)
		conn.Add(prof_in)

		status = http.StatusOK

	} else {
		auth.SessionSave(c)
		auth.Login(c)
	}

	c.JSON(status, prof_in.Comments)
}
Example #2
0
File: app.go Project: sankark/kyp
func Admin(c *gin.Context) {
	if auth.IsAuthenticated(c) {
		c.HTML(http.StatusOK, "admin.html", gin.H{})
	} else {
		auth.Login(c)
	}

}