Exemple #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
}
Exemple #2
0
// 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
}
Exemple #3
0
// 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
}
Exemple #4
0
// 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
}
Exemple #5
0
// 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
}
Exemple #6
0
// 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
}
Exemple #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
}
Exemple #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
}