Ejemplo n.º 1
0
func (c *ArticleController) EditArticle() {
	id, _ := c.GetInt64(":id")
	userId := c.CurrentUserId()
	c.TplName = "article_edit.html"

	beego.Error("id:", id)
	if id <= 0 {
		c.StringError("文章不存在")
		return
	}

	if userId <= 0 {
		c.Redirect("/users/login", 302)
		return
	}

	article, error := services.ArticleByIdAndUserId(id, userId)

	if nil != error {
		c.StringError("文章不存在")
	} else {
		c.Data["article"] = article
		c.SetCategories(article.UserId)
		c.SetKeywords(article.Categories + "," + article.Tags)
		var subLength = services.ParameterIntValue("seo-description-length")
		c.SetDescription(article.ShortContent(subLength)).SetTitle(article.Title)
	}
}
Ejemplo n.º 2
0
func (c *BaseController) NeedCheckCaptcha() bool {
	sessionId := c.CruSession.SessionID()

	failTimes := services.ParameterIntValue("no_captcha_login_fail_times")

	failTimesCache := redis_util.IncrByWithTimeOut(sessionId, failTimes, int64(time.Second*3))

	return failTimesCache > failTimes
}
Ejemplo n.º 3
0
func (c *BaseController) RecordLoginFailTimes() {
	sessionId := c.CruSession.SessionID()

	failTimes := services.ParameterIntValue("no_captcha_login_fail_times")

	failTimesCache := redis_util.IncrByWithTimeOut(sessionId, 1, int64(time.Second*3))

	if failTimesCache >= failTimes {
		c.Data["showCaptcha"] = true
	}
}
Ejemplo n.º 4
0
func (c *ArticleController) ArticleDetail() {

	id, _ := c.GetInt64(":id")
	ip := c.Ip()
	userId, _ := c.GetInt64(":userId")

	c.TplName = "article_detail.html"

	if id <= 0 {
		c.StringError("文章不存在")
		c.Ctx.Redirect(302, "/")
		return
	}

	host := c.Host()
	url := c.Ctx.Request.RequestURI

	reqUri := fmt.Sprintf("%s%s", host, url)

	c.Data["reqUri"] = reqUri

	article, error := services.ArticleById(id)

	if error == nil {
		writer, _ := services.User(article.UserId)
		article.User = writer
	}

	if userId > 0 {
		hasLike, err := services.HasLikeArticle(id, userId, db.NewDB())
		if nil == err {
			article.HasLike = hasLike
		}
	}

	if nil != error {
		c.StringError("文章不存在")
	} else {
		currUserId := c.CurrentUserId()
		success, _ := services.IncrViewCount(id, currUserId, ip)
		if success {
			article.ViewCount = article.ViewCount + 1
		}
		c.Data["article"] = article

		c.SetCategories(article.UserId)

		c.SetKeywords(article.Categories + "," + article.Tags)
		var subLength = services.ParameterIntValue("seo-description-length")
		c.SetDescription(article.ShortContent(subLength)).SetTitle(article.Title)
	}
}