예제 #1
0
func ReviewAdminCreatePost(c *gin.Context) {
	session := sessions.Default(c)
	db := models.GetDB()

	c.Request.ParseMultipartForm(32 << 20)
	review := &models.Review{}
	if c.Bind(review) == nil {
		review.ArticleID = helpers.Atouintr(c.Request.FormValue("article_id"))
		if mpartFile, mpartHeader, err := c.Request.FormFile("image"); err == nil {
			defer mpartFile.Close()
			review.Image, err = saveFile(mpartHeader, mpartFile)
			if err != nil {
				c.HTML(500, "errors/500", helpers.ErrorData(err))
				return
			}
		}

		if err := db.Create(review).Error; err != nil {
			c.HTML(400, "errors/400", helpers.ErrorData(err))
			return
		}
		c.Redirect(303, "/admin/reviews")
	} else {
		session.AddFlash("Ошибка! Проверьте внимательно заполнение всех полей!")
		session.Save()
		c.Redirect(303, "/admin/new_review")
	}
}
예제 #2
0
//CommentCreatePost handles /new_comment route
func CommentCreatePost(c *gin.Context) {
	session := sessions.Default(c)
	db := models.GetDB()

	comment := &models.Comment{}
	if c.Bind(comment) == nil {
		//simple captcha check
		captcha, err := base64.StdEncoding.DecodeString(comment.Captcha)
		if err != nil {
			c.HTML(500, "errors/500", helpers.ErrorData(err))
			return
		}
		if string(captcha) != "100.00" {
			c.HTML(400, "errors/400", nil)
			return
		}
		comment.Published = false //leave unpublished
		if err := db.Create(comment).Error; err != nil {
			c.HTML(400, "errors/400", helpers.ErrorData(err))
			return
		}
		notifyAdminOfComment(comment)
		session.AddFlash("Спасибо! Ваш вопрос будет опубликован после проверки.")
		session.Save()
		c.Redirect(303, fmt.Sprintf("/articles/%d#comments", comment.ArticleID))
	} else {
		session.AddFlash("Ошибка! Внимательно проверьте заполнение всех полей!")
		session.Save()
		c.Redirect(303, "/")
	}
}
예제 #3
0
func ReviewUpdatePost(c *gin.Context) {
	session := sessions.Default(c)
	db := models.GetDB()

	c.Request.ParseMultipartForm(32 << 20)
	review := &models.Review{}
	if err := c.Bind(review); err == nil {

		if mpartFile, mpartHeader, err := c.Request.FormFile("image"); err == nil {
			defer mpartFile.Close()
			review.Image, err = saveFile(mpartHeader, mpartFile)
			if err != nil {
				c.HTML(500, "errors/500", helpers.ErrorData(err))
				return
			}
		}

		if err := db.Model(&models.Review{}).Updates(review).Error; err != nil {
			session.AddFlash(err.Error())
			session.Save()
			c.Redirect(303, c.Request.RequestURI)
			return
		}
		session.AddFlash("Отзыв был успешно сохранен")
	} else {
		log.Println(err)
		session.AddFlash("Ошибка! Внимательно проверьте заполнение всех полей")
	}
	session.Save()
	c.Redirect(303, "/reviews")
}
예제 #4
0
//ReviewUpdate handles /edit_review?token=:secure_token route
func ReviewUpdateGet(c *gin.Context) {
	session := sessions.Default(c)
	flashes := session.Flashes()
	session.Save()
	db := models.GetDB()

	id := getIDFromToken(c.Request.FormValue("token"))
	review := &models.Review{}
	db.First(review, id)
	if review.ID == 0 || review.Published {
		err := fmt.Errorf("Отзыв не найден или уже был опубликован и не подлежит редактированию")
		c.HTML(404, "errors/404", helpers.ErrorData(err))
		return
	}

	var articles []models.Article
	db.Where("published = ?", true).Find(&articles)
	review.Published = true //set default to true
	c.HTML(200, "reviews/form", gin.H{
		"Title":      "Редактировать отзыв",
		"Articles":   articles,
		"Active":     "reviews",
		"Review":     review,
		"SecureEdit": true,
		"Flash":      flashes,
	})
}
예제 #5
0
func ReviewCreatePost(c *gin.Context) {
	db := models.GetDB()
	session := sessions.Default(c)

	c.Request.ParseMultipartForm(32 << 20)
	review := &models.Review{}
	if c.Bind(review) == nil {
		//simple captcha check
		captcha, err := base64.StdEncoding.DecodeString(review.Captcha)
		if err != nil {
			c.HTML(500, "errors/500", helpers.ErrorData(err))
			return
		}
		if string(captcha) != "100.00" {
			c.HTML(400, "errors/400", nil)
			return
		}
		review.Published = false

		if mpartFile, mpartHeader, err := c.Request.FormFile("image"); err == nil {
			defer mpartFile.Close()
			review.Image, err = saveFile(mpartHeader, mpartFile)
			if err != nil {
				c.HTML(500, "errors/500", helpers.ErrorData(err))
				return
			}
		}

		if err := db.Create(review).Error; err != nil {
			c.HTML(400, "errors/400", helpers.ErrorData(err))
			return
		}
		notifyAdminOfReview(review)
		session.AddFlash("Спасибо! Ваш отзыв будет опубликован после проверки.")
	} else {
		session.AddFlash("Ошибка! Внимательно проверьте заполнение всех полей!")
	}
	session.Save()
	c.Redirect(303, "/reviews")
}
예제 #6
0
//ArticlesAdminIndex handles GET /admin/articles route
func ArticlesAdminIndex(c *gin.Context) {
	db := models.GetDB()

	var list []models.Article
	if err := db.Order("published desc, id desc").Find(&list).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.HTML(200, "articles/admin/index", gin.H{
		"Title":  "Статьи",
		"Active": "articles",
		"List":   list,
	})
}
예제 #7
0
//UserAdminDelete handles /admin/delete_user route
func UserAdminDelete(c *gin.Context) {
	db := models.GetDB()

	user := &models.User{}
	db.First(user, c.Request.PostFormValue("id"))
	if user.ID == 0 {
		c.HTML(404, "errors/404", nil)
	}

	if err := db.Delete(user).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.Redirect(303, "/admin/users")
}
예제 #8
0
//PageAdminDelete handles /admin/delete_page route
func PageAdminDelete(c *gin.Context) {
	db := models.GetDB()

	page := &models.Page{}
	db.First(page, c.Request.PostFormValue("id"))
	if page.ID == 0 {
		c.HTML(404, "errors/404", nil)
	}

	if err := db.Delete(page).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.Redirect(303, "/admin/pages")
}
예제 #9
0
//ReviewAdminDelete handles /admin/delete_review route
func ReviewAdminDelete(c *gin.Context) {
	db := models.GetDB()

	review := &models.Review{}
	db.First(review, c.Request.PostFormValue("id"))
	if review.ID == 0 {
		c.HTML(404, "errors/404", nil)
	}

	if err := db.Delete(review).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.Redirect(303, "/admin/reviews")
}
예제 #10
0
//ArticlesIndex handles GET /articles route
func ArticlesIndex(c *gin.Context) {
	db := models.GetDB()

	var list []models.Article
	if err := db.Where("published = ?", true).Order("id desc").Find(&list).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.HTML(200, "articles/index", gin.H{
		"Title":           "Кинезиология во врачебной практике",
		"Active":          c.Request.RequestURI,
		"List":            list,
		"MetaDescription": "Статьи о кинезиологической практике лечения заболеваний опорно-двигательного аппарата...",
		"MetaKeywords":    "кинезиология, статьи, лечение болей, прикладная кинезиология",
	})
}
예제 #11
0
//ArticleAdminDelete handles /admin/delete_article route
func ArticleAdminDelete(c *gin.Context) {
	db := models.GetDB()

	article := &models.Article{}
	db.First(article, c.Request.PostFormValue("id"))
	if article.ID == 0 {
		c.HTML(404, "errors/404", nil)
		return
	}

	if err := db.Delete(article).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.Redirect(303, "/admin/articles")
}
예제 #12
0
//CommentAdminDelete handles /admin/delete_comment route
func CommentAdminDelete(c *gin.Context) {
	db := models.GetDB()

	comment := &models.Comment{}
	db.First(comment, c.Request.PostFormValue("id"))
	if comment.ID == 0 {
		c.HTML(404, "errors/404", nil)
	}

	if err := db.Delete(comment).Error; err != nil {
		c.HTML(500, "errors/500", helpers.ErrorData(err))
		return
	}
	c.Redirect(303, "/admin/comments")

}