Beispiel #1
0
// Create 发布新资源
func (ResourceController) Create(ctx echo.Context) error {
	title := ctx.FormValue("title")
	// 请求新建资源页面
	if title == "" || ctx.Request().Method() != "POST" {
		return render(ctx, "resources/new.html", map[string]interface{}{"activeResources": "active", "categories": logic.AllCategory})
	}

	errMsg := ""
	resForm := ctx.FormValue("form")
	if resForm == model.LinkForm {
		if ctx.FormValue("url") == "" {
			errMsg = "url不能为空"
		}
	} else {
		if ctx.FormValue("content") == "" {
			errMsg = "内容不能为空"
		}
	}
	if errMsg != "" {
		return fail(ctx, 1, errMsg)
	}

	me := ctx.Get("user").(*model.Me)
	err := logic.DefaultResource.Publish(ctx, me, ctx.FormParams())
	if err != nil {
		return fail(ctx, 2, "内部服务错误,请稍候再试!")
	}

	return success(ctx, nil)
}
Beispiel #2
0
// Modify 修改主题
func (TopicController) Modify(ctx echo.Context) error {
	tid := goutils.MustInt(ctx.FormValue("tid"))
	if tid == 0 {
		return ctx.Redirect(http.StatusSeeOther, "/topics")
	}

	nodes := logic.GenNodes()

	if ctx.Request().Method() != "POST" {
		topics := logic.DefaultTopic.FindByTids([]int{tid})
		if len(topics) == 0 {
			return ctx.Redirect(http.StatusSeeOther, "/topics")
		}

		return render(ctx, "topics/new.html", map[string]interface{}{"nodes": nodes, "topic": topics[0], "activeTopics": "active"})
	}

	me := ctx.Get("user").(*model.Me)
	err := logic.DefaultTopic.Publish(ctx, me, ctx.FormParams())
	if err != nil {
		if err == logic.NotModifyAuthorityErr {
			return fail(ctx, 1, "没有权限操作")
		}

		return fail(ctx, 2, "服务错误,请稍后重试!")
	}
	return success(ctx, nil)
}
Beispiel #3
0
func defaultCacheKeyAlgorithm(ctx echo.Context) string {
	filter := map[string]bool{
		"from":      true,
		"sign":      true,
		"nonce":     true,
		"timestamp": true,
	}
	form := ctx.FormParams()
	var keys = make([]string, 0, len(form))
	for key := range form {
		if _, ok := filter[key]; !ok {
			keys = append(keys, key)
		}
	}

	sort.Sort(sort.StringSlice(keys))

	buffer := goutils.NewBuffer()
	for _, k := range keys {
		buffer.Append(k).Append("=").Append(ctx.FormValue(k))
	}

	req := ctx.Request()
	return goutils.Md5(req.Method() + req.URL().Path() + buffer.String())
}
Beispiel #4
0
// Create 评论(或回复)
func (CommentController) Create(ctx echo.Context) error {
	user := ctx.Get("user").(*model.Me)

	// 入库
	objid := goutils.MustInt(ctx.Param("objid"))
	comment, err := logic.DefaultComment.Publish(ctx, user.Uid, objid, ctx.FormParams())
	if err != nil {
		return fail(ctx, 1, "服务器内部错误")
	}

	return success(ctx, comment)
}
Beispiel #5
0
// New 新建规则
func (RuleController) New(ctx echo.Context) error {
	var data = make(map[string]interface{})

	if ctx.FormValue("submit") == "1" {
		user := ctx.Get("user").(*model.Me)

		errMsg, err := logic.DefaultRule.Save(ctx, ctx.FormParams(), user.Username)
		if err != nil {
			return fail(ctx, 1, errMsg)
		}
		return success(ctx, nil)
	}

	return render(ctx, "rule/new.html", data)
}
Beispiel #6
0
// Create 创建wiki页
func (WikiController) Create(ctx echo.Context) error {
	title := ctx.FormValue("title")
	// 请求新建 wiki 页面
	if title == "" || ctx.Request().Method() != "POST" {
		return render(ctx, "wiki/new.html", map[string]interface{}{"activeWiki": "active"})
	}

	me := ctx.Get("user").(*model.Me)
	err := logic.DefaultWiki.Create(ctx, me, ctx.FormParams())
	if err != nil {
		return fail(ctx, 1, "内部服务错误")
	}

	return success(ctx, nil)
}
Beispiel #7
0
// Create 新建项目
func (ProjectController) Create(ctx echo.Context) error {
	name := ctx.FormValue("name")
	// 请求新建项目页面
	if name == "" || ctx.Request().Method() != "POST" {
		project := &model.OpenProject{}
		return render(ctx, "projects/new.html", map[string]interface{}{"project": project, "activeProjects": "active"})
	}

	user := ctx.Get("user").(*model.Me)
	err := logic.DefaultProject.Publish(ctx, user, ctx.FormParams())
	if err != nil {
		return fail(ctx, 1, "内部服务错误!")
	}
	return success(ctx, nil)
}
Beispiel #8
0
// Create 新建主题
func (TopicController) Create(ctx echo.Context) error {
	nodes := logic.GenNodes()

	title := ctx.FormValue("title")
	// 请求新建主题页面
	if title == "" || ctx.Request().Method() != "POST" {
		return render(ctx, "topics/new.html", map[string]interface{}{"nodes": nodes, "activeTopics": "active"})
	}

	me := ctx.Get("user").(*model.Me)
	err := logic.DefaultTopic.Publish(ctx, me, ctx.FormParams())
	if err != nil {
		return fail(ctx, 1, "内部服务错误")
	}

	return success(ctx, nil)
}
Beispiel #9
0
// Like 喜欢(或取消喜欢)
func (LikeController) Like(ctx echo.Context) error {
	form := ctx.FormParams()
	if !util.CheckInt(form, "objtype") || !util.CheckInt(form, "flag") {
		return fail(ctx, 1, "参数错误")
	}

	user := ctx.Get("user").(*model.Me)
	objid := goutils.MustInt(ctx.Param("objid"))
	objtype := goutils.MustInt(ctx.FormValue("objtype"))
	likeFlag := goutils.MustInt(ctx.FormValue("flag"))

	err := logic.DefaultLike.LikeObject(ctx, user.Uid, objid, objtype, likeFlag)
	if err != nil {
		return fail(ctx, 2, "服务器内部错误")
	}

	return success(ctx, nil)
}
Beispiel #10
0
// Modify 编辑规则
func (self RuleController) Modify(ctx echo.Context) error {
	var data = make(map[string]interface{})

	if ctx.FormValue("submit") == "1" {
		user := ctx.Get("user").(*model.Me)

		errMsg, err := logic.DefaultRule.Save(ctx, ctx.FormParams(), user.Username)
		if err != nil {
			return fail(ctx, 1, errMsg)
		}
		return success(ctx, nil)
	}

	rule := logic.DefaultRule.FindById(ctx, ctx.QueryParam("id"))
	if rule == nil {
		return ctx.Redirect(http.StatusSeeOther, ctx.Echo().URI(echo.HandlerFunc(self.RuleList)))
	}

	data["rule"] = rule

	return render(ctx, "rule/modify.html", data)
}
Beispiel #11
0
// Publish
func (ReadingController) Publish(ctx echo.Context) error {
	var data = make(map[string]interface{})

	if ctx.FormValue("submit") == "1" {
		user := ctx.Get("user").(*model.Me)
		errMsg, err := logic.DefaultReading.SaveReading(ctx, ctx.FormParams(), user.Username)
		if err != nil {
			return fail(ctx, 1, errMsg)
		}
		return success(ctx, nil)
	}

	id := goutils.MustInt(ctx.QueryParam("id"))
	if id != 0 {
		reading := logic.DefaultReading.FindById(ctx, id)
		if reading != nil {
			data["reading"] = reading
		}
	}

	return render(ctx, "reading/modify.html", data)
}
Beispiel #12
0
// Modify 修改项目
func (ProjectController) Modify(ctx echo.Context) error {
	id := goutils.MustInt(ctx.FormValue("id"))
	if id == 0 {
		return ctx.Redirect(http.StatusSeeOther, "/projects")
	}

	// 请求编辑项目页面
	if ctx.Request().Method() != "POST" {
		project := logic.DefaultProject.FindOne(ctx, id)
		return render(ctx, "projects/new.html", map[string]interface{}{"project": project, "activeProjects": "active"})
	}

	user := ctx.Get("user").(*model.Me)
	err := logic.DefaultProject.Publish(ctx, user, ctx.FormParams())
	if err != nil {
		if err == logic.NotModifyAuthorityErr {
			return ctx.String(http.StatusForbidden, "没有权限")
		}
		return fail(ctx, 1, "内部服务错误!")
	}
	return success(ctx, nil)
}
Beispiel #13
0
// Modify 修改資源
func (ResourceController) Modify(ctx echo.Context) error {
	id := goutils.MustInt(ctx.FormValue("id"))
	if id == 0 {
		return ctx.Redirect(http.StatusSeeOther, "/resources/cat/1")
	}

	// 请求编辑資源页面
	if ctx.Request().Method() != "POST" {
		resource := logic.DefaultResource.FindResource(ctx, id)
		return render(ctx, "resources/new.html", map[string]interface{}{"resource": resource, "activeResources": "active", "categories": logic.AllCategory})
	}

	me := ctx.Get("user").(*model.Me)
	err := logic.DefaultResource.Publish(ctx, me, ctx.FormParams())
	if err != nil {
		if err == logic.NotModifyAuthorityErr {
			return ctx.String(http.StatusForbidden, "没有权限修改")
		}
		return fail(ctx, 2, "内部服务错误,请稍候再试!")
	}

	return success(ctx, nil)
}
Beispiel #14
0
// Modify
func (self ArticleController) Modify(ctx echo.Context) error {
	var data = make(map[string]interface{})

	if ctx.FormValue("submit") == "1" {
		user := ctx.Get("user").(*model.Me)
		errMsg, err := logic.DefaultArticle.Modify(ctx, user, ctx.FormParams())
		if err != nil {
			return fail(ctx, 1, errMsg)
		}
		return success(ctx, nil)
	}
	article, err := logic.DefaultArticle.FindById(ctx, ctx.QueryParam("id"))
	if err != nil {
		return ctx.Redirect(http.StatusSeeOther, ctx.Echo().URI(echo.HandlerFunc(self.ArticleList)))
	}

	data["article"] = article
	data["statusSlice"] = model.ArticleStatusSlice
	data["langSlice"] = model.LangSlice

	return render(ctx, "article/modify.html", data)

}