Exemple #1
0
func (cc *CommentController) Post() {
	form := new(CommentForm)
	if err := cc.Validator.Validate(form, cc); err != nil {
		cc.JSONError(200, err)
		return
	}
	form.Type = cc.Param("type")
	form.Id = cc.ParamInt64("id")

	// create comment object
	var (
		c = new(model.Comment)
	)
	if err := service.Call(service.Comment.Create, form.toCreateOption(), c); err != nil {
		cc.JSONError(200, err)
		return
	}

	// save comment object
	if err := service.Call(service.Comment.Save, c, c); err != nil {
		cc.JSONError(200, err)
		return
	}

	cc.JSON(map[string]interface{}{
		"comment": model.NewFrontComment(c),
	})
}
Exemple #2
0
func (ac *ArticleController) Get() {
	var (
		article = new(model.Article)
		opt     = service.ArticleReadOption{
			Id:        ac.ParamInt64(":id"),
			Link:      ac.Param(":link"),
			Status:    model.ARTICLE_STATUS_PUBLISH,
			IsHit:     true,
			IsPublish: true,
		}
		opt2 = service.CommentListOption{
			From:   model.COMMENT_FROM_ARTICLE,
			Status: 0,
		}
		comments = make([]*model.Comment, 0)
	)
	if err := service.Call(service.Article.Read, opt, article); err != nil {
		status := 500
		if err == service.ErrArticleNotFound {
			status = 404
		}
		ac.RenderError(status, err)
		return
	}
	if article.Id != opt.Id || article.Link != opt.Link {
		ac.RenderError(404, nil)
		return
	}
	opt2.FromId = article.Id
	if service.Setting.Comment.ShowWaitComment {
		opt2.AllAccessible = true
	} else {
		opt2.AllApproved = true
	}
	if err := service.Call(service.Comment.ListForContent, opt2, &comments); err != nil {
		ac.RenderError(500, err)
		return
	}

	shouldShowComments := true
	if article.IsCommentClosed() && len(comments) == 0 {
		shouldShowComments = false
	}

	if ac.AuthUser != nil {
		ac.Assign(middle.AuthUserTemplateField, nil) // set auth user nil instead of middleware assignment
		ac.Assign("FrontUser", model.NewFrontUser(ac.AuthUser))
	}

	ac.Title(article.Title + " - " + service.Setting.General.Title)
	ac.Assign("Article", article)
	ac.Assign("Comments", comments)
	ac.Assign("ShouldShowComments", shouldShowComments)
	ac.Assign("IsCommentEnable", article.IsCommentable(service.Setting.Comment.AutoCloseDay))
	ac.Assign("CommentUrl", fmt.Sprintf("/comment/article/%d", article.Id))
	ac.Assign("XsrfHTML", ac.XsrfFormHtml())
	ac.Render("single.tmpl")
}
Exemple #3
0
func (aic *AdvImportController) Post() {
	opt := service.ImportOption{
		User: aic.AuthUser,
	}
	t := strings.ToLower(aic.Param("type"))
	if t == "goblog" {
		opt.Type = service.IMPORT_TYPE_GOBLOG

		_, h, err := aic.Req().FormFile("file")
		if err != nil {
			aic.JSONError(500, err)
			return
		}

		savePath := fmt.Sprintf("_temp/%s", h.Filename)
		if err := os.MkdirAll(path.Dir(savePath), os.ModePerm); err != nil {
			aic.JSONError(500, err)
			return
		}
		if err := aic.SaveToFile("file", savePath); err != nil {
			aic.JSONError(500, err)
			return
		}
		opt.TempFile = savePath
		if err := service.Call(service.Import.Import, opt); err != nil {
			aic.JSONError(500, err)
			return
		}
	}
	aic.JSON(nil)
}
Exemple #4
0
func (pc *PageController) Get() {
	pageLink := pc.Param(":link")
	if len(pageLink) == 0 {
		pc.RenderError(404, nil)
		return
	}
	var (
		page = new(model.Page)
		opt  = service.PageReadOption{
			Id:        pc.ParamInt64(":id"),
			Link:      pageLink,
			Status:    model.PAGE_STATUS_PUBLISH,
			IsHit:     true,
			IsPublish: true,
		}
	)
	if err := service.Call(service.Page.Read, opt, page); err != nil {
		status := 500
		if err == service.ErrPageNotFound {
			status = 404
		}
		pc.RenderError(status, err)
		return
	}
	if page.Link != pageLink {
		pc.RenderError(404, nil)
		return
	}
	pc.Title(page.Title + " - " + service.Setting.General.Title)
	pc.Assign("Page", page)
	pc.Render(page.Template)
}
Exemple #5
0
func (t *AdminRender) SetTheme(*model.Theme) error {
	var theme = new(model.Theme)
	if err := service.Call(service.Theme.Admin, nil, theme); err != nil {
		return err
	}
	t.baseTheme.SetTheme(theme)
	return nil
}
Exemple #6
0
func (rc *RssController) Get() {
	var buf bytes.Buffer
	if err := service.Call(service.RSS.RSS, nil, &buf); err != nil {
		panic(err)
	}
	rc.Header().Add("Content-Type", "application/rss+xml;charset=UTF-8")
	rc.Write(buf.Bytes())
}
Exemple #7
0
func (apc *ArticlePublicController) Get() {
	if id := apc.FormInt64("id"); id > 0 {
		if err := service.Call(service.Article.ToPublish, &id); err != nil {
			apc.RenderError(500, err)
			return
		}
	}
	apc.Redirect(apc.Req().Referer())
}
Exemple #8
0
func (adc *ArticleDeleteController) Get() {
	id := adc.FormInt64("id")
	if id > 0 {
		if err := service.Call(service.Article.Delete, id); err != nil {
			adc.RenderError(500, err)
			return
		}
	}
	adc.Redirect(adc.Req().Referer())
}
Exemple #9
0
func (stc *SettingThemeController) Get() {
	themes := make([]*model.Theme, 0)
	if err := service.Call(service.Theme.All, nil, &themes); err != nil {
		stc.RenderError(500, err)
		return
	}
	stc.Title("THEME - PUGO")
	stc.Assign("Themes", themes)
	stc.Render("setting_theme.tmpl")
}
Exemple #10
0
func (pdc *PageDeleteController) Get() {
	id := pdc.FormInt64("id")
	if id > 0 {
		if err := service.Call(service.Page.Delete, id); err != nil {
			pdc.RenderError(500, err)
			return
		}
	}
	pdc.Redirect(pdc.Req().Referer())
}
Exemple #11
0
func (mdc *MediaDeleteController) Get() {
	id := mdc.FormInt64("id")
	if id > 0 {
		if err := service.Call(service.Media.Delete, id); err != nil {
			mdc.RenderError(500, err)
			return
		}
	}
	mdc.Redirect(mdc.Req().Referer())
}
Exemple #12
0
func (lc *LoginController) Logout() {
	if token := lc.ReadToken(lc.Context); token != "" {
		if err := service.Call(service.User.Unauthorize, &token); err != nil {
			lc.RenderError(500, err)
			return
		}
	}
	lc.WriteToken(lc.Context, nil)
	lc.Redirect("/admin/login")
}
Exemple #13
0
func (sm *SettingMenuController) Post() {
	menuSettings := []*model.SettingMenu{}
	form := sm.Req().Form
	if err := service.Call(service.Setting.CreateMenu, form, &menuSettings); err != nil {
		sm.JSONError(200, err)
		return
	}
	setting := &model.Setting{
		Name:   "menu",
		UserId: 0,
		Type:   model.SETTING_TYPE_MENU,
	}
	setting.Encode(menuSettings)
	if err := service.Call(service.Setting.Write, setting); err != nil {
		sm.JSONError(200, err)
		return
	}
	service.Setting.Menu = menuSettings
	sm.JSON(nil)
}
Exemple #14
0
func (cc *CommentController) Reply() {
	c := &model.Comment{
		UserId:   cc.AuthUser.Id,
		Body:     cc.Form("content"),
		ParentId: cc.FormInt64("pid"),
	}
	if err := service.Call(service.Comment.Reply, c); err != nil {
		cc.RenderError(500, err)
		return
	}
	cc.Redirect("/admin/manage/comment")
}
Exemple #15
0
func Install(ctx *cli.Context) {
	opt := service.BootstrapInitOption{true, false, false}
	if err := service.Call(service.Bootstrap.Init, opt); err != nil {
		log15.Crit("Install.fail", "error", err)
	}
	if core.Cfg.Install == "0" {
		log15.Info("Install.start")
		opt = service.BootstrapInitOption{false, true, false} // connect to database
		if err := service.Call(service.Bootstrap.Init, opt); err != nil {
			log15.Crit("Install.fail", "error", err)
		}
		opt2 := newBootstrapInstallOption(ctx)
		if err := service.Call(service.Bootstrap.Install, opt2); err != nil {
			log15.Crit("Install.fail", "error", err)
		}
		log15.Info("Install.finish")
		return
	}
	i, _ := strconv.ParseInt(core.Cfg.Install, 10, 64)
	log15.Warn("Install.HadInstalled", "version", core.Cfg.Version, "installed", time.Unix(i, 0))
}
Exemple #16
0
func (cc *CommentController) Delete() {
	if id := cc.FormInt64("id"); id > 0 {
		opt := service.CommentSwitchOption{
			Id:     id,
			Status: model.COMMENT_STATUS_DELETED,
		}
		if err := service.Call(service.Comment.SwitchStatus, opt); err != nil {
			cc.RenderError(500, err)
			return
		}
	}
	cc.Redirect(cc.Req().Referer())
}
Exemple #17
0
func (abc *AdvBackupController) Backup() {
	opt := service.BackupOption{
		true, true, true, true,
	}
	fileName := ""
	if err := service.Call(service.Backup.Backup, opt, &fileName); err != nil {
		abc.JSONError(200, err)
		return
	}
	abc.JSON(map[string]interface{}{
		"file": fileName,
	})
}
Exemple #18
0
func (ac *ArchiveController) Get() {
	ac.Title("Archive - " + service.Setting.General.Title)
	var (
		opt      = service.ArchiveListOption{}
		archives = make([]*model.ArticleArchive, 0)
	)
	if err := service.Call(service.Article.Archive, opt, &archives); err != nil {
		ac.RenderError(500, err)
		return
	}
	ac.Assign("Archives", archives)
	ac.Render("archive.tmpl")
}
Exemple #19
0
func (pc *ProfileController) Post() {
	form := new(ProfileForm)
	if err := pc.Validator.Validate(form, pc); err != nil {
		pc.JSONError(200, err)
		return
	}
	user := form.toUser()
	user.Id = pc.AuthUser.Id
	if err := service.Call(service.User.Profile, user); err != nil {
		pc.JSONError(200, err)
		return
	}
	pc.JSON(nil)
}
Exemple #20
0
func (pc *ProfileController) Password() {
	form := new(PasswordForm)
	if err := pc.Validator.Validate(form, pc); err != nil {
		pc.JSONError(200, err)
		return
	}
	opt := form.toOption()
	opt.User = pc.AuthUser
	if err := service.Call(service.User.Password, opt); err != nil {
		pc.JSONError(200, err)
		return
	}
	pc.JSON(nil)
}
Exemple #21
0
func (mc *MediaController) uploadFormEditor(opt service.MediaUploadOption) {
	m := new(model.Media)
	if err := service.Call(service.Media.Upload, opt, m); err != nil {
		mc.JSONRaw(map[string]interface{}{
			"success": 0,
			"message": err.Error(),
		})
		return
	}
	mc.JSONRaw(map[string]interface{}{
		"success": 1,
		"url":     "/" + m.FilePath,
	})
}
Exemple #22
0
func (abc *AdvBackupController) Get() {
	if file := abc.Form("file"); file != "" {
		abc.ServeFile(file)
		return
	}

	files := make([]*model.BackupFile, 0)
	if err := service.Call(service.Backup.Files, nil, &files); err != nil {
		abc.RenderError(500, err)
		return
	}
	abc.Title("BACKUP - PUGO")
	abc.Assign("BackupFiles", files)
	abc.Render("advance_backup.tmpl")
}
Exemple #23
0
func (pwc *PageWriteController) Get() {
	pwc.Title("WRITE PAGE - PUGO")
	pwc.Assign("XsrfHTML", pwc.XsrfFormHtml())
	if id := pwc.FormInt64("id"); id > 0 {
		var (
			opt  = service.PageReadOption{Id: id}
			page = new(model.Page)
		)
		if err := service.Call(service.Page.Read, opt, page); err != nil {
			pwc.RenderError(500, err)
			return
		}
		pwc.Assign("Page", page)
	}
	pwc.Render("write_page.tmpl")
}
Exemple #24
0
func (awc *ArticleWriteController) Get() {
	awc.Title("WRITE ARTICLE - PUGO")
	awc.Assign("XsrfHTML", awc.XsrfFormHtml())
	if id := awc.FormInt64("id"); id > 0 {
		var (
			opt     = service.ArticleReadOption{Id: id}
			article = new(model.Article)
		)
		if err := service.Call(service.Article.Read, opt, article); err != nil {
			awc.RenderError(500, err)
			return
		}
		awc.Assign("Article", article)
	}
	awc.Render("write_article.tmpl")
}
Exemple #25
0
func (awc *ArticleWriteController) Post() {
	form := new(ArticleForm)
	if err := awc.Validator.Validate(form, awc); err != nil {
		awc.JSONError(200, err)
		return
	}
	form.UserId = awc.AuthUser.Id
	var article = new(model.Article)
	if err := service.Call(service.Article.Write, form.toArticle(), article); err != nil {
		awc.JSONError(200, err)
		return
	}
	awc.JSON(map[string]interface{}{
		"article": article,
	})
}
Exemple #26
0
func (mc *MediaController) Upload() {
	opt := service.MediaUploadOption{
		Ctx:      mc.Ctx,
		User:     mc.AuthUser.Id,           // media's owner int
		FormName: mc.Form("field", "file"), // form field name
	}
	if mc.Form("from") == "editor" {
		mc.uploadFormEditor(opt)
		return
	}
	if err := service.Call(service.Media.Upload, opt); err != nil {
		mc.JSONError(500, err)
		return
	}
	mc.JSON(nil)
}
Exemple #27
0
func (mc *MediaController) Get() {
	var (
		opt        = service.MediaListOption{IsCount: true}
		mediaFiles = make([]*model.Media, 0)
		pager      = new(utils.Pager)
	)
	if err := service.Call(service.Media.List, opt, &mediaFiles, pager); err != nil {
		mc.RenderError(500, err)
		return
	}
	mc.Assign("MediaFiles", mediaFiles)
	mc.Assign("Pager", pager)
	mc.Title("MEDIA - PUGO")
	mc.Assign("MaxSize", service.Setting.Media.MaxFileSize/1024)
	mc.Render("manage_media.tmpl")
}
Exemple #28
0
func (pwc *PageWriteController) Post() {
	form := new(PagePostForm)
	if err := pwc.Validator.Validate(form, pwc); err != nil {
		pwc.JSONError(200, err)
		return
	}
	form.UserId = pwc.AuthUser.Id
	var page = new(model.Page)
	if err := service.Call(service.Page.Write, form.toPage(), page); err != nil {
		pwc.JSONError(200, err)
		return
	}
	pwc.JSON(map[string]interface{}{
		"page": page,
	})
}
Exemple #29
0
func (cc *CommentController) Get() {
	cc.Title("COMMENT - " + strings.ToUpper(core.PUGO_NAME))
	var (
		opt = service.CommentListOption{
			Page:    cc.FormInt("page", 1),
			Size:    cc.FormInt("size", 10),
			IsCount: true,
		}
		comments = make([]*model.Comment, 0)
		pager    = new(utils.Pager)
	)

	// load comment
	switch cc.Form("status") {
	case "all":
		opt.Status = 0
	case "approved":
		opt.Status = model.COMMENT_STATUS_APPROVED
	case "wait":
		opt.Status = model.COMMENT_STATUS_WAIT
	case "spam":
		opt.Status = model.COMMENT_STATUS_SPAM
	default:
		opt.Status = 0
	}
	if err := service.Call(service.Comment.List, opt, &comments, pager); err != nil {
		cc.RenderError(500, err)
		return
	}

	// build pager url
	query := cc.Req().URL.Query()
	query.Del("page")
	queryStr := query.Encode()
	if len(queryStr) == 0 {
		queryStr = "/admin/manage/comment?page=%d"
	} else {
		queryStr = "/admin/manage/comment?" + queryStr + "&page=%d"
	}

	cc.Assign("PageUrl", queryStr)
	cc.Assign("Comments", comments)
	cc.Assign("Pager", pager)
	cc.Render("manage_comment.tmpl")
}
Exemple #30
0
func (pmc *PageManageController) Get() {
	pmc.Title("PAGES - PUGO")
	var (
		opt = service.PageListOption{
			IsCount: true,
			Page:    pmc.FormInt("page", 0),
		}
		pages = make([]*model.Page, 0)
		pager = new(utils.Pager)
	)
	if err := service.Call(service.Page.List, opt, &pages, pager); err != nil {
		pmc.RenderError(500, err)
		return
	}
	pmc.Assign("Pages", pages)
	pmc.Assign("Pager", pager)
	pmc.Render("manage_page.tmpl")
}