Exemplo n.º 1
0
func (tc *TorrentController) Episodes() *web.Result {

	outData := &struct {
		EpisodeList  []*models.EpisodeBundle
		ShowEpisodes bool
	}{
		EpisodeList:  models.LatestEpisodes(),
		ShowEpisodes: true,
	}

	// Respond with?
	result := &web.Result{Status: 200}

	if strings.Contains(tc.acceptHeader, "application/json") {
		// marshal
		jsonResponse, err := json.Marshal(outData.EpisodeList)
		if err != nil {
			result.Status = 500
			result.Body = []byte("error formatting json for resp.")
			return result
		}

		result.Body = jsonResponse
	} else {
		result.Body = []byte(web.RenderWith(
			"bootstrap",
			"torrent",
			"tv",
			outData,
			tc.Flash))
	}

	return result
}
Exemplo n.º 2
0
Arquivo: home.go Projeto: frazy/babou
// Private route - rendered instead of public index if the user
// is properly authenticated.
func (hc *HomeController) blog() *web.Result {
	output := &web.Result{Status: 200}

	testArticles := make([]*struct{ Text string }, 0)
	testArticles = append(testArticles, &struct{ Text string }{Text: "what up bro?"})
	testArticles = append(testArticles, &struct{ Text string }{Text: "JUST WHO THE HELL DO YOU THINK I AM??"})

	user, err := hc.auth.CurrentUser()
	if err != nil {
		fmt.Printf("error printing user: %s \n", err.Error())
		output.Status = 500
		return output
	}

	outData := &struct {
		Username string
		Articles []*struct{ Text string }
	}{
		Username: user.Username,
		Articles: testArticles,
	}

	output.Body = []byte(web.RenderWith("bootstrap", "home", "news", outData))

	return output
}
Exemplo n.º 3
0
Arquivo: login.go Projeto: frazy/babou
// Displays the login page.
func (lc *LoginController) Index() *web.Result {
	output := &web.Result{}

	output.Status = 200
	outData := &web.ViewData{Context: &struct{}{}}

	output.Body = []byte(web.RenderWith("bootstrap", "login", "index", outData, lc.Flash))

	return output
}
Exemplo n.º 4
0
Arquivo: login.go Projeto: frazy/babou
// Displays the registration form.
func (lc *LoginController) New() *web.Result {
	output := &web.Result{}

	output.Status = 200
	outData := &web.ViewData{Context: &struct{}{}} // render the registration form.

	output.Body = []byte(web.RenderWith("bootstrap", "login", "new", outData, lc.Flash))

	return output
}
Exemplo n.º 5
0
Arquivo: home.go Projeto: frazy/babou
// Public route - rendered as a public index if the user
// is not logged in or is not authenticated.
func (hc *HomeController) homePage() *web.Result {
	output := &web.Result{Status: 200}
	outData := &struct{}{}

	output.Body = []byte(web.RenderWith(
		"bootstrap",
		"home",
		"index",
		outData, hc.Flash))
	return output
}
Exemplo n.º 6
0
Arquivo: home.go Projeto: frazy/babou
// Displays the "about us" page & contact info.
func (hc *HomeController) Faq() *web.Result {
	output := &web.Result{Status: 200}

	// TODO: dump markdown formatted blurb.
	user, err := hc.auth.CurrentUser()
	if err != nil {
		fmt.Printf("error printing user: %s \n", err.Error())
		output.Status = 500
		return output
	}

	outData := &struct {
		Username string
	}{
		Username: user.Username,
	}

	output.Body = []byte(web.RenderWith("bootstrap", "home", "faq", outData))

	return output
}
Exemplo n.º 7
0
// Displays a form where a user can upload a new torrent.
func (tc *TorrentController) New() *web.Result {
	//TODO: permission check; for now any authenticated user can add torrents.
	redirect, user := tc.RedirectOnAuthFail()
	if user == nil {
		return redirect
	}

	output := &web.Result{Status: 200}
	outData := &struct {
		Username    string
		AnnounceURL string
	}{
		Username:    user.Username,
		AnnounceURL: user.AnnounceURL(),
	}

	// Display new torrent form.
	output.Body = []byte(web.RenderWith("bootstrap", "torrent", "new", outData, tc.Flash))

	return output
}
Exemplo n.º 8
0
func (tc *TorrentController) Index() *web.Result {
	// Private page.
	redirect, user := tc.RedirectOnAuthFail()
	if user == nil {
		return redirect
	}

	output := &web.Result{Status: 200}
	outData := &struct {
		Username    string
		TorrentList []*models.Torrent
	}{
		Username: user.Username,
	}

	allTorrents := &models.Torrent{}
	torrentList, err := allTorrents.SelectSummaryPage()
	if err != nil {
		output.Body = []byte(err.Error())
		return output
	}

	for _, t := range torrentList {
		stats := tc.events.ReadStats(t.InfoHash)
		if stats == nil {
			continue
		}

		t.Seeding = stats.Seeding
		t.Leeching = stats.Leeching
	}

	outData.TorrentList = torrentList

	output.Body = []byte(web.RenderWith("bootstrap", "torrent", "index", outData, tc.Flash))

	return output
}