func (this *NArticleController) Del() { id, err := this.GetInt("id") if err != nil { this.Ctx.WriteString("get param id fail") return } b := blog.NOneById(int64(id)) if b == nil { this.Ctx.WriteString("no such article") return } if this.UserName != b.Creator && !this.IsAdmin { this.Ctx.WriteString("you are not author or admin") return } err = blog.NDel(b) if err != nil { this.Ctx.WriteString(err.Error()) return } this.Ctx.WriteString("del success") return }
func (this *NArticleController) Edit() { id, err := this.GetInt("id") if err != nil { this.Ctx.WriteString("get param id fail") return } b := blog.NOneById(int64(id)) if b == nil { this.Ctx.WriteString("no such article") return } if this.UserName != b.Creator && !this.IsAdmin { this.Ctx.WriteString("you are not author or admin") return } this.Data["Content"] = blog.NReadBlogContent(b).Content this.Data["Blog"] = b tmp := catalog.NAll() this.Data["Catalogs"] = tmp p := "" for _, v := range tmp { if b.CatalogId == v.Id { p = v.Ident } } if p != "" { this.Data["RedirectPath"] = "/newemployee/catalog/" + p } else { this.Data["RedirectPath"] = "/newemployee" } this.Data["ReturnPath"] = this.Data["RedirectPath"] this.Layout = "main_newemployee/layout/admin.html" this.TplNames = "main_newemployee/article/edit.html" }
func (this *NArticleController) DoEdit() { if !this.IsLogin && !this.IsAdmin { this.Ctx.WriteString("you are not the admin or author") return } id, err := this.GetInt("id") if err != nil { this.Ctx.WriteString("get param id fail") return } b := blog.NOneById(int64(id)) if b == nil { this.Ctx.WriteString("no such article") return } if this.UserName != b.Creator && !this.IsAdmin { this.Ctx.WriteString("you are not author or admin") return } title := this.GetString("title") ident := this.GetString("ident") keywords := this.GetString("keywords") catalog_id := this.GetIntWithDefault("catalog_id", -1) aType := this.GetIntWithDefault("type", -1) status := this.GetIntWithDefault("status", -1) content := this.GetString("content") if catalog_id == -1 || aType == -1 || status == -1 { this.Ctx.WriteString("catalog || type || status is illegal") return } if title == "" || ident == "" { this.Ctx.WriteString("title or ident is blank") return } cp := catalog.NOneById(int64(catalog_id)) if cp == nil { this.Ctx.WriteString("catalog_id not exists") return } b.Ident = ident b.Title = title b.Keywords = keywords b.CatalogId = int64(catalog_id) b.Type = int8(aType) b.Status = int8(status) err = blog.NUpdate(b, content) if err != nil { this.Ctx.WriteString(err.Error()) return } this.Ctx.WriteString("success") this.JsStorage("deleteKey", "post/edit") this.Redirect("/newemployee/catalog/"+cp.Ident, 302) return }