示例#1
0
func Album(args martini.Params, su models.User, session sessions.Session, r render.Render, dbh *db.Dbh, p *models.Page) {
	name := args["name"]
	auser := args["user"]
	key := args["key"]

	if auser != "" {
		log.Println("album user: "******"flash", "Login Required")
		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "login"}, "/"), http.StatusFound)
		return
	}

	images := dbh.GetAllImagesByAlbumId(album.Id)

	var imageLinks []imageLink
	for _, f := range images {
		if f.Trashed {
			continue
		}
		var file_name = f.Name
		if f.HashId != "" {
			file_name = f.HashId
		}
		log.Println(file_name, f)
		imageLinks = append(imageLinks, imageLink{Id: f.Id, Title: f.Name, FileName: file_name, Owner: f.User})
	}

	p.SetTitle("Album", name)
	p.SetUser(su)
	p.Data = AlbumVars{Title: name, Description: album.Description, ImageLinks: imageLinks}

	encoder.Render(p.Encoding, 200, "image_link", p, r)
}
示例#2
0
func AlbumDelete(args martini.Params, req *http.Request, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {
	// Default status
	var result string = "Not Deleted"
	var status string = "Permission Denied"
	var code int = 401

	name := args["name"]

	album := dbh.GetAlbumByName(name)
	if album.User == su.Id {
		status = "Success"
		result = "Deleted"
		dAlbum := dbh.AlbumDelete(album)
		log.Printf("%+v", dAlbum)
	}
	if album.Id == 0 {
		status = "Album not found"
		code = 404
	}

	p.Data = models.AlbumResult{Name: name, Result: result, Status: status}
	log.Println("Album Delete: User: "******" Album: ", name, " Result: ", result, " Status: ", status)
	encoder.Render("json", code, "", p, r)
}