Exemple #1
0
func (this *NewsController) Insert(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Insert")

	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Insert news")
		return
	}

	this.Init(w, r)

	if this.Privilege != config.PrivilegeAD {
		this.Err400(w, r, "Warning", "Error Privilege to Insert news")
		return
	}

	one := model.News{}
	one.Title = r.FormValue("title")
	one.Content = template.HTML(r.FormValue("content"))

	newsModel := model.NewsModel{}
	err := newsModel.Insert(one)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/admin/news?list", http.StatusFound)
}
Exemple #2
0
//@URL: /admin/news/ @method:POST
func (nc *AdminNews) Insert() {
	restweb.Logger.Debug("Admin News Insert")

	if nc.Privilege != config.PrivilegeAD {
		nc.Err400("Warning", "Error Privilege to Insert news")
		return
	}

	one := model.News{}
	one.Title = nc.R.FormValue("title")
	one.Content = template.HTML(nc.Input.Get("content"))

	newsModel := model.NewsModel{}
	err := newsModel.Insert(one)
	if err != nil {
		nc.Error(err.Error(), 500)
		return
	}

	nc.Redirect("/admin/news", http.StatusFound)
}