Example #1
0
func (this *AuthorController) ByName() {
	this.TplName = "author.tpl"

	author_name := this.Ctx.Input.Param(":name")

	if post_count, err := models.NewPostModel().Count("Author__AuthorName", author_name); err == nil {
		paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)
		if author, err := models.NewAuthorModel().ByName(author_name); err == nil {
			this.Data["Author"] = author
			posts, err := models.NewPostModel().ByAuthorId(author.AuthorId, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
			if err != nil {
				panic(err)
			}

			this.SetPostViews(posts)
			this.LoadSidebar([]string{"LatestComments", "MostPopular"})

			this.Data["Posts"] = posts
			this.Data["PageTitle"] = fmt.Sprintf("%s - Author - %s", author.DisplayName, blogTitle)
		} else {
			this.Abort("404")
		}
	} else {
		panic(err)
	}
}
Example #2
0
File: base.go Project: migege/milog
func (this *BaseController) Prepare() {
	this.startTime = time.Now()
	ts := strconv.FormatInt(time.Now().UnixNano(), 10)
	this.Data["TimeStamp"] = ts

	options := models.NewOptionModel().Names(&[]string{
		models.OPTION_BLOG_TITLE,
		models.OPTION_BLOG_DESC,
		models.OPTION_BLOG_URL,
		models.OPTION_POSTS_PER_PAGE,
	})
	blogTitle = options[models.OPTION_BLOG_TITLE].OptionValue
	blogDesc = options[models.OPTION_BLOG_DESC].OptionValue
	blogUrl = options[models.OPTION_BLOG_URL].OptionValue
	if postsPerPage, _ = options[models.OPTION_POSTS_PER_PAGE].GetInt(); postsPerPage < 1 {
		postsPerPage = 10
	}

	this.Data["BlogTitle"] = blogTitle
	this.Data["BlogDesc"] = blogDesc
	this.Data["BlogUrl"] = blogUrl

	if u, err := url.Parse(blogUrl); err == nil {
		this.Data["BlogHost"] = u.Host
	}

	logged_username := this.GetSession(SESS_NAME)
	if logged_username == nil {
		logged_username, res := this.GetSecureCookie(COOKIE_SECURE_KEY_USER, COOKIE_NAME_LOGGED_USER)
		if res == true {
			if logged_user, err := models.NewAuthorModel().ByName(fmt.Sprintf("%s", logged_username)); err == nil {
				this.SetSession(SESS_NAME, logged_username)
				this.Data["LoggedUser"] = logged_user
				this.loggedUser = logged_user
			}
		}
	} else {
		if logged_user, err := models.NewAuthorModel().ByName(fmt.Sprintf("%s", logged_username)); err == nil {
			this.Data["LoggedUser"] = logged_user
			this.loggedUser = logged_user
		}
	}

	this.Data["GoVersion"] = runtime.Version()
}
Example #3
0
func (this *AuthorController) ById() {
	author_id_str := this.Ctx.Input.Param(":id")
	author_id, _ := strconv.Atoi(author_id_str)
	author, err := models.NewAuthorModel().ById(author_id)
	if err != nil {
		this.Abort("404")
	}
	this.Redirect(fmt.Sprintf("/author/%s", author.AuthorName), 301)
}
Example #4
0
func (this *LoginController) DoLogin() {
	ret := struct {
		Code    int
		Message string
	}{0, "success"}
	username := this.GetString("log")
	password := this.GetString("pwd")
	ts := this.GetString("ts")
	err := models.NewAuthorModel().Validate(ts, username, password)
	if err == nil {
		this.SetSession(SESS_NAME, username)
	} else {
		ret.Code = 1
		ret.Message = err.Error()
	}
	this.Data["json"] = &ret
	this.ServeJSON()
}