Beispiel #1
0
func (this *OptionController) DoEdit() {
	err := models.NewOptionModel().Save(this.Input())
	if err != nil {
		panic(err)
	}

	this.Redirect("/admin/options", 302)
}
Beispiel #2
0
func (this *OptionController) setOptionsData(names *[]string) {
	options_map := models.NewOptionModel().Names(names)
	var options []*models.Option
	for _, option := range options_map {
		options = append(options, option)
	}
	this.Data["Options"] = options
}
Beispiel #3
0
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()
}