예제 #1
0
//@URL: /admin/news/(\d+)/ @method: POST
func (nc *AdminNews) Update(Nid string) {
	restweb.Logger.Debug("Admin News Update")

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

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

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

	err = newsModel.Update(nid, one)
	if err != nil {
		nc.Error(err.Error(), 500)
		return
	} else {
		nc.Redirect("/admin/news", http.StatusFound)
	}
}
예제 #2
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)
}
예제 #3
0
//@URL: /admin/news/(\d+)/status/ @method: POST
func (nc *AdminNews) Status(Nid string) {
	restweb.Logger.Debug("Admin News Status")

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

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	nc.Redirect("/admin/news", http.StatusFound)
}
예제 #4
0
func (this *NewsController) Update(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Update")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Update news")
		return
	}

	this.Init(w, r)

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

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

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

	err = newsModel.Update(nid, one)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	} else {
		http.Redirect(w, r, "/admin/news?detail/nid?"+strconv.Itoa(nid), http.StatusFound)
	}
}
예제 #5
0
func (this *NewsController) Edit(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Edit")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	this.Data["Detail"] = one
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	this.Data["Title"] = "Admin - News Edit"
	this.Data["IsNews"] = true
	this.Data["IsList"] = false
	this.Data["IsEdit"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/news_edit.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
예제 #6
0
// 删除指定新闻
func (this *NewsController) Delete(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Delete")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Delete news")
		return
	}

	this.Init(w, r)

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

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	err = newsModel.Delete(nid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	w.WriteHeader(200)
}
예제 #7
0
// 列出所有新闻
//@URL: /admin/news/ @method: GET
func (nc *AdminNews) List() {
	restweb.Logger.Debug("Admin News List")

	newsModel := model.NewsModel{}
	newlist, err := newsModel.List(-1, -1)
	if err != nil {
		nc.Error(err.Error(), 500)
		return
	}
	nc.Output["News"] = newlist
	nc.Output["Title"] = "Admin - News List"
	nc.Output["IsNews"] = true
	nc.Output["IsList"] = true
	nc.RenderTemplate("view/admin/layout.tpl", "view/admin/news_list.tpl")
}
예제 #8
0
//列出所有新闻
//@URL: /news @method: GET
func (nc *NewsController) List() {
	restweb.Logger.Debug("News List")

	newsModel := model.NewsModel{}
	newsList, err := newsModel.List(-1, -1)
	if err != nil {
		// http.Error(w, err.Error(), 500)
		return
	}
	nc.Output["News"] = newsList

	nc.Output["Title"] = "Welcome to ZJGSU Online Judge"
	nc.Output["IsNews"] = true
	nc.RenderTemplate("view/layout.tpl", "view/news_list.tpl")
}
예제 #9
0
func (this *NewsController) Status(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Status")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to change news status")
		return
	}

	this.Init(w, r)

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

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	http.Redirect(w, r, "/admin/news?list", http.StatusFound)
}
예제 #10
0
//列出所有新闻
func (this *NewsController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("News List")
	this.Init(w, r)

	newsModel := model.NewsModel{}
	newsList, err := newsModel.List(-1, -1)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	this.Data["News"] = newsList

	this.Data["Title"] = "Welcome to ZJGSU Online Judge"
	this.Data["IsNews"] = true
	err = this.Execute(w, "view/layout.tpl", "view/news_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
예제 #11
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)
}
예제 #12
0
//@URL: /news/(\d+) @method: GET
func (nc *NewsController) Detail(Nid string) {
	nid, err := strconv.Atoi(Nid) //获取nid
	if err != nil {
		// http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	if err != nil {
		http.Error(nc.W, err.Error(), 500)
	}
	nc.Output["Detail"] = one

	if one.Status == config.StatusReverse {
		nc.Err400("No such news", "No such news")
		return
	}

	nc.Output["Title"] = "News Detail"
	nc.RenderTemplate("view/layout.tpl", "view/news_detail.tpl")
}
예제 #13
0
// 删除指定新闻
//@URL: /admin/news/(\d+)/ @method: DELETE
func (nc *AdminNews) Delete(Nid string) {
	restweb.Logger.Debug("Admin News Delete")

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

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	err = newsModel.Delete(nid)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}

	nc.W.WriteHeader(200)
}
예제 #14
0
//列出指定新闻的详细信息
func (this *NewsController) Detail(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("News Detail")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"]) //获取nid
	if err != nil {
		class.Logger.Debug(args["nid"])
		http.Error(w, "args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	this.Data["Detail"] = one

	if one.Status == config.StatusReverse && this.Privilege != config.PrivilegeAD { //如果news的状态为普通用户不可见
		this.Data["Title"] = "No such news"
		this.Data["Info"] = "No such news"
		err = this.Execute(w, "view/layout.tpl", "view/400.tpl")
		if err != nil {
			http.Error(w, "tpl error", 500)
			return
		}
		return
	}

	this.Data["Title"] = "News Detail"
	err = this.Execute(w, "view/layout.tpl", "view/news_detail.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
예제 #15
0
//@URL: /admin/news/(\d+)/ @method: GET
func (nc *AdminNews) Edit(Nid string) {
	restweb.Logger.Debug("Admin News Edit")

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModel := model.NewsModel{}
	one, err := newsModel.Detail(nid)
	nc.Output["Detail"] = one
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}

	nc.Output["Title"] = "Admin - News Edit"
	nc.Output["IsNews"] = true
	nc.Output["IsList"] = false
	nc.Output["IsEdit"] = true

	nc.RenderTemplate("view/admin/layout.tpl", "view/admin/news_edit.tpl")
}
예제 #16
0
//@URL: / @method: GET
func (hc *HomeController) Index() {
	restweb.Logger.Debug("Home")

	newsModel := model.NewsModel{}
	newsList, err := newsModel.List(-1, -1)
	if err != nil {
		hc.Error(err.Error(), 500)
		return
	}
	hc.Output["News"] = newsList
	hc.Output["Title"] = "Welcome to ZJGSU Online Judge"
	hc.Output["IsNews"] = true

	ojModel := &model.OJModel{}
	list, err := ojModel.List()
	if err == nil {
		for _, l := range list {
			restweb.Logger.Debug(*l)
		}
		hc.Output["OJStatus"] = list
	}

	hc.RenderTemplate("view/layout.tpl", "view/news_list.tpl")
}