Example #1
0
func CreateUser(username, password string) error {
	hash := sha1.New()
	io.WriteString(hash, password)
	user := new(User)
	user.Username = username
	user.Password = fmt.Sprintf("%x", hash.Sum(nil))
	_, err := db.Upsert(user)
	return err
}
Example #2
0
func (e *Entry) SummaryRender() string {
	if len(e.SummaryRendered) > 0 && !conf.Config.Debug {
		return e.SummaryRendered
	}
	var ret string
	var data obj
	b := []byte(e.Data)
	json.Unmarshal(b, &data)

	template_name := fmt.Sprintf("blog/stream/%s-summary.mandira", e.Type)

	if e.Type == "twitter" {
		ret = template.Render(template_name, obj{"Entry": e, "Tweet": data["tweet"]})
	} else if e.Type == "github" {
		event := data["event"].(map[string]interface{})
		var hash string
		if event["id"] != nil {
			hash = event["id"].(string)[:8]
		} else if event["sha"] != nil {
			hash = event["sha"].(string)[:8]
		} else {
			hash = "unknown"
		}
		eventType := event["event"].(string)
		isCommit := eventType == "commit"
		isCreate := eventType == "create"
		isFork := eventType == "fork"
		ret = template.Render(template_name, obj{
			"Entry":    e,
			"Event":    event,
			"Hash":     hash,
			"IsCommit": isCommit,
			"IsCreate": isCreate,
			"IsFork":   isFork,
		})
	} else if e.Type == "bitbucket" {
		// TODO: check username (author) against configured bitbucket username
		update := data["update"].(map[string]interface{})
		revision := fmt.Sprintf("#%d", update["revision"].(float64))
		var repository obj
		if data["repository"] != nil {
			repository = data["repository"].(obj)
		}
		ret = template.Render(template_name, obj{
			"Entry":      e,
			"Data":       data,
			"Update":     update,
			"Repository": repository,
			"Revision":   revision})
	}
	e.SummaryRendered = ret
	if !conf.Config.Debug {
		db.Upsert(e)
	}
	return ret
}
Example #3
0
func (p *PicasaAPI) UpdatePhotos(album *PicasaAlbum) error {
	photos, err := p.ListPhotos(album)
	if err != nil {
		return err
	}
	for _, photo := range photos {
		db.Upsert(photo)
	}
	return nil
}
Example #4
0
// Update all picasa album info
func (p *PicasaAPI) UpdateAlbums() error {
	albums, err := p.ListAlbums()
	if err != nil {
		return err
	}
	for _, album := range albums {
		db.Upsert(album)
	}
	return nil
}
Example #5
0
func pageEdit(ctx *web.Context, url string) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}
	var page *Page
	err := db.Find(page, M{"url": url}).One(&page)
	if err != nil {
		fmt.Println(err)
		ctx.Redirect(302, "/admin/")
		return ""
	}
	if len(ctx.Params) > 1 {
		page.FromParams(ctx.Params)
		db.Upsert(page)
	}
	return adminBase.Render("blog/admin/pages-edit.mandira", page)
}
Example #6
0
func pageAdd(ctx *web.Context) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}

	if ctx.Request.Method == "GET" {
		ctx.Params["Url"] = strings.TrimLeft(ctx.Params["Url"], "/")
		return adminBase.Render("blog/admin/pages-edit.mandira", ctx.Params)
	}

	var page = new(Page)
	page.FromParams(ctx.Params)
	db.Upsert(page)
	ctx.Redirect(302, "/admin/")
	return ""
	//ctx.Redirect(302, "/admin/posts/edit/" + post.Slug + "/")
}
Example #7
0
func postAdd(ctx *web.Context) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}

	if ctx.Request.Method == "GET" {
		return adminBase.Render("blog/admin/posts-edit.mandira",
			ctx.Params, M{"Published": 0, "IsPublished": false})
	}

	post := new(Post)
	post.FromParams(ctx.Params)
	_, err := db.Upsert(post)
	if err != nil {
		fmt.Println(err)
	}
	ctx.Redirect(302, "/admin/")
	return ""
	//ctx.Redirect(302, "/admin/posts/edit/" + post.Slug + "/")
}
Example #8
0
func postEdit(ctx *web.Context, slug string) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}
	var post *Post
	err := db.Find(post, M{"slug": slug}).One(&post)
	if err != nil {
		fmt.Println(err)
		ctx.Redirect(302, "/admin/")
		return ""
	}
	if len(ctx.Params) > 1 {
		post.FromParams(ctx.Params)
		db.Upsert(post)
	}

	return adminBase.Render("blog/admin/posts-edit.mandira", post, M{
		"IsPublished": post.Published == 1,
		"IdHex":       post.Id.Hex()})
}
Example #9
0
// Render the post, using the cached ContentRendered if available, or generating
// and re-saving it to the database if not
func RenderPost(post *Post) string {
	if len(post.ContentRendered) == 0 {
		db.Upsert(post)
	}
	return template.Render("blog/post.mandira", post)
}