Ejemplo n.º 1
0
func HandleIndex(r render.Render) {
	tip := models.Tips{}

	db := GetDBInstance()
	total, err := db.C("tips").Count()

	if err != nil || total == 0 {
		r.HTML(200, "500", nil)
		return
	}

	index := getRandomIndex(total)

	if index == total {
		index = total - 1
	}

	db.C("tips").Find(nil).Skip(index).One(&tip)

	if db.Session != nil {
		defer db.Session.Close()
	}

	r.HTML(200, "index", map[string]interface{}{
		"Comment": tip.Comment,
		"Content": tip.Content,
		"Id":      tip.Id.Hex(),
		"IsIndex": true})
}
func handleTemplate(r render.Render, req *http.Request, t Template, s ServerList) {
	tmpl_data := make(map[string]interface{})
	tmpl_data["title"] = t.Title
	tmpl_data["server"] = getServerInfo(req, s)

	r.HTML(200, t.Tmpl, tmpl_data)
}
func SearchAnswersNew(r render.Render, db *mgo.Database, req *http.Request, session sessions.Session) {
	lastGameIdSearched := session.Get("last_game_id_searched")

	templateData := map[string]interface{}{"metatitle": "Battle Answers", "currentPath": req.URL.Path,
		"lastGameIdSearched": lastGameIdSearched, "games": models.GetGameRecs(db, nil)}
	r.HTML(200, "search_answers/new", templateData)
}
Ejemplo n.º 4
0
func EventListHandler(r render.Render) {

	search := bson.M{"data.start_time": bson.M{"$gte": time.Now()}}
	sort := "data.start_time"
	var results []Event
	err := db.Find(&Event{}, search).Sort(sort).All(&results)
	if err != nil && err != mgo.ErrNotFound {
		panic(err)
	}

	if err == mgo.ErrNotFound {
		fmt.Println("No such object in db. Redirect")
		//http.Redirect(w, r, "/404/", http.StatusFound)
		return
	}

	type templateData struct {
		Context *conf.Context
		Events  []Event
	}

	data := templateData{conf.DefaultContext(conf.Config), results}

	r.HTML(200, "event_list", data)

}
Ejemplo n.º 5
0
/////////////////////////////////////////////////////////////////////////////////////////////
// Controller Actions
/////////////////////////////////////////////////////////////////////////////////////////////
func GamesIndex(r render.Render, db *mgo.Database, req *http.Request) {
	var recs []models.GameRec

	recs = models.GetGameRecs(db, nil)

	templateData := map[string]interface{}{"metatitle": "Battle Answers", "currentPath": req.URL.Path,
		"recs": populateGameDisplays(db, recs)}
	r.HTML(200, "games/index", templateData)
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Controller Actions
/////////////////////////////////////////////////////////////////////////////////////////////
func BattleAnswersIndex(r render.Render, db *mgo.Database, req *http.Request) {
	var recs []models.BattleAnswerRec

	recs = models.GetBattleAnswerRecs(db, nil)

	templateData := map[string]interface{}{"metatitle": "Battle Answers", "currentPath": req.URL.Path,
		"recs": helpers.GetBattleAnswerDisplays(db, recs)}
	r.HTML(200, "battle_answers/index", templateData)
}
Ejemplo n.º 7
0
func NotFoundHandler(r render.Render) {

	type templateData struct {
		Context *conf.Context
	}

	data := templateData{conf.DefaultContext(conf.Config)}

	r.HTML(200, "404", data)
}
Ejemplo n.º 8
0
func HomeHandler(r render.Render) {

	type templateData struct {
		Context *conf.Context
	}

	data := templateData{conf.DefaultContext(conf.Config)}

	r.HTML(200, "home", data)
}
Ejemplo n.º 9
0
func EventGrabHandler(r render.Render) {

	type templateData struct {
		Context *conf.Context
	}

	data := templateData{conf.DefaultContext(conf.Config)}

	r.HTML(200, "event_grab", data)

}
Ejemplo n.º 10
0
func AdminModifyCasts(r render.Render, db *mgo.Database, params martini.Params) {

	cast := models.Casts{}

	db.C("casts").FindId(bson.ObjectIdHex(params["Id"])).One(&cast)

	r.HTML(200, "admin/casts_modify", map[string]interface{}{
		"IsCasts": true,
		"Id":      params["Id"],
		"Cast":    cast}, render.HTMLOptions{Layout: "admin/layout"})
}
Ejemplo n.º 11
0
// Render error page
func renderError(code int, r render.Render) {
	r.HTML(404, "404", Page{
		HttpCode:    404,
		HttpMethod:  "GET",
		Template:    "404",
		Path:        "/404",
		Slug:        "404",
		Title:       "Página não encontrada - Hera Modas",
		Description: "A página que você tentou acessar não existe ou foi removida.",
	})
}
Ejemplo n.º 12
0
func Login(r *http.Request, render render.Render, db *gorp.DbMap, s sessions.Session) {
	user := User{}
	email, password := r.FormValue("email"), r.FormValue("password")
	err := db.SelectOne(&user, "Select * from users where email=? ", email)
	//tmp_pass, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	//err := db.QueryRow("select id, password from users where email=$1", email).Scan(&userId, &dbPasswd)
	if err != nil || bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) != nil {
		render.HTML(400, "404", "")
	}
	s.Set("userId", user.Id)
	render.HTML(200, "dashboard", "")
}
Ejemplo n.º 13
0
func ShowLoginPage(r render.Render, s sessions.Session) {

	isLogin := s.Get("IsLogin")

	if isLogin != nil {
		r.Redirect("/admin/index")
		return
	}

	r.HTML(200, "admin/login", map[string]interface{}{
		"IsAbout": true}, render.HTMLOptions{})
}
Ejemplo n.º 14
0
func markdownHandler(w render.Render, r *http.Request, p martini.Params) {
	page, lang := p["_1"], p["lang"]

	if len(page) == 0 {
		page = "home"
	}
	if len(lang) == 0 {
		lang = "en"
	}

	model := NewMarkdown(lang, page)
	w.HTML(200, model.Template, model)
}
Ejemplo n.º 15
0
func FacebookLoginHandler(r render.Render) {

	// simple static page for user to click on fb connect button

	type templateData struct {
		Context *conf.Context
	}

	data := templateData{conf.DefaultContext(conf.Config)}

	r.HTML(200, "facebook_login", data)

}
Ejemplo n.º 16
0
// Render - Method for rendering main html page
func (dotviz *DotVizController) Render(r render.Render, params martini.Params) {
	data := params["data"]
	dotvizresp := new(dotVizResponse)

	if data != "" {
		dotvizresp.FromBase64(data)
	} else {
		// dotvizresp.FromBase64("TXlTdHJpbmdXV1c=")
		// dotvizresp.FromBase64("Z3JhcGggewphIC0tIGIgYSAtLSBiICBiIC0tIGEgIHIgLS0gZwp9Cg==")
		dotvizresp.FromString("graph {\n  a -- b  \n}")
	}

	r.HTML(200, "dotviz", dotvizresp)
}
Ejemplo n.º 17
0
func HandleTip(r render.Render, params martini.Params) {
	db := GetDBInstance()
	tip := models.Tips{}

	db.C("tips").FindId(bson.ObjectIdHex(params["Id"])).One(&tip)

	if db.Session != nil {
		defer db.Session.Close()
	}

	r.HTML(200, "tip", map[string]interface{}{
		"Comment": tip.Comment,
		"Content": tip.Content,
		"Id":      tip.Id.Hex()})
}
Ejemplo n.º 18
0
/////////////////////////////////////////////////////////////////////////////////////////////
// Controller Actions
/////////////////////////////////////////////////////////////////////////////////////////////
func SearchAnswersIndex(r render.Render, db *mgo.Database, gameId string, keywords string, req *http.Request) {
	var game models.GameRec
	var recs []models.BattleAnswerRec
	var tags []string

	models.FindGameById(db, gameId, &game)

	tags = strings.Split(keywords, " ")

	recs = models.GetBattleAnswerRecs(db, bson.M{"gameid": gameId, "tags": bson.M{"$all": tags}})

	templateData := map[string]interface{}{"metatitle": "Battle Answers", "currentPath": req.URL.Path, "game": game,
		"keywords": keywords,
		"recs":     helpers.GetBattleAnswerDisplays(db, recs)}
	r.HTML(200, "search_answers/index", templateData)
}
Ejemplo n.º 19
0
// Product details router
func (gs *Shop) RouteProduct(params martini.Params, r render.Render) {
	category := params["category"]
	slug := params["product"]

	if category == "" || slug == "" {
		// if there are no paramters, render 404 error
		renderError(404, r)
	} else {
		// look for the product
		if product, err := gs.GetProduct(category, slug); err == nil {
			r.HTML(200, "product", product)
		} else {
			// product not found
			renderError(404, r)
		}
	}
}
Ejemplo n.º 20
0
// Category router
func (gs *Shop) RouteCategory(params martini.Params, r render.Render) {
	slug := params["category"]

	if slug == "" {
		// if there is no parameter, render 404 error
		renderError(404, r)
	} else {
		// look for the category and their products
		if category, err := gs.GetCategory(slug, true); err == nil {
			// render category page
			r.HTML(200, "category", category)
		} else {
			// category not found
			renderError(404, r)
		}
	}
}
Ejemplo n.º 21
0
func HandleAdminIndex(r render.Render, db *mgo.Database) {
	tips_count, err := db.C("tips").Count()

	if err != nil {
		tips_count = 0
	}

	casts_count, err := db.C("casts").Count()

	if err != nil {
		casts_count = 0
	}

	r.HTML(200, "admin/index", map[string]interface{}{
		"IsIndex":    true,
		"TipsCount":  tips_count,
		"CastsCount": casts_count}, render.HTMLOptions{Layout: "admin/layout"})
}
Ejemplo n.º 22
0
func RegIndex(r render.Render) {
	checkUrl := getRegisterUrl()
	fmt.Printf("checkUrl: %s\n", checkUrl)
	index := strings.Index(checkUrl, "nocach=") + 7
	filename := checkUrl[index:index+10] + ".png"
	saveCheckImg(checkUrl, filename)
	log.Println("checkUrl filename", checkUrl, filename)
	gUser.CheckCode = "/images/" + filename
	for i, user := range gUser.Users {
		log.Printf("%d-%v\n", i, user)
		if user.RegStatus != StatusSuccess {
			gUser.CurUserName = user.UserName
			gUser.CurPassWord = user.PassWord
			break
		}
	}
	r.HTML(200, "index", gUser)
}
Ejemplo n.º 23
0
func ShowEventAttendees(params martini.Params, mdb *mgo.Database, r render.Render) {

	fmt.Println("Show event attendees")

	var attendees []Attendee
	fmt.Println(params["eid"])
	mdb.C("attendees").Find(bson.M{"eid": params["eid"]}).All(&attendees)

	type templateData struct {
		Context   *conf.Context
		Attendees []Attendee
	}

	data := templateData{conf.DefaultContext(conf.Config), attendees}

	r.HTML(200, "event_attendees", data)

}
Ejemplo n.º 24
0
func AdminShowTips(req *http.Request, r render.Render, db *mgo.Database, pager *paginate.Paginator) {
	num, _ := db.C("tips").Count()

	pers := 12
	pager.Init(pers, num)

	tips := []models.Tips{}
	viewTips := []models.TipsView{}

	db.C("tips").Find(nil).Limit(pers).Skip(pager.Offset()).All(&tips)

	for _, t := range tips {
		viewTips = append(viewTips, models.TipsView{Id: t.Id.Hex(), Content: t.Content, Comment: t.Comment})
	}

	r.HTML(200, "admin/tips_index", map[string]interface{}{
		"IsTips":    true,
		"Tips":      viewTips,
		"Paginator": pager,
		"Num":       num}, render.HTMLOptions{Layout: "admin/layout"})
}
Ejemplo n.º 25
0
func HandleAPI(r render.Render) {
	db := GetDBInstance()
	txt_api := models.API{}
	json_api := models.API{}

	err := db.C("apis").Find(bson.M{"type": "txt"}).One(&txt_api)

	if err != nil {
		r.HTML(200, "500", nil)
		return
	}

	err = db.C("apis").Find(bson.M{"type": "json"}).One(&json_api)

	if err != nil {
		r.HTML(200, "500", nil)
		return
	}

	r.HTML(200, "api", map[string]interface{}{
		"IsAPI":       true,
		"TxtCounter":  txt_api.Count,
		"JsonCounter": json_api.Count})

	if db.Session != nil {
		defer db.Session.Close()
	}
}
Ejemplo n.º 26
0
func EventNextHandler(r render.Render) {

	search := bson.M{"data.start_time": bson.M{"$gte": time.Now()}}
	sort := "data.start_time"
	var results []Event
	err := db.Find(&Event{}, search).Sort(sort).Limit(2).All(&results)
	fmt.Println(results)

	if err != nil && err != mgo.ErrNotFound {
		panic(err)
	}

	type templateData struct {
		Context *conf.Context
		Events  []Event
	}

	data := templateData{conf.DefaultContext(conf.Config), results}

	r.HTML(200, "event_next", data)

}
Ejemplo n.º 27
0
func AdminShowCasts(r render.Render, db *mgo.Database, pager *paginate.Paginator) {
	num, _ := db.C("casts").Count()

	pers := 12
	pager.Init(pers, num)

	casts := []models.Casts{}
	viewCasts := []models.CastsView{}

	db.C("casts").Find(nil).Limit(pers).Skip(pager.Offset()).All(&casts)

	for _, t := range casts {
		viewCasts = append(viewCasts,
			models.CastsView{Id: t.Id.Hex(), Author: t.Author, AuthorUrl: t.AuthorUrl,
				VisitCount: t.VisitCount, Title: t.Title, Intro: template.HTML(t.Intro), ShowNotes: template.HTML(t.ShowNotes), Url: t.Url, LogoUrl: t.LogoUrl})
	}

	r.HTML(200, "admin/casts_index", map[string]interface{}{
		"IsCasts":   true,
		"Casts":     viewCasts,
		"Paginator": pager,
		"Num":       num}, render.HTMLOptions{Layout: "admin/layout"})
}
Ejemplo n.º 28
0
func HandleCasts(r render.Render, pager *paginate.Paginator) {

	db := GetDBInstance()

	num, _ := db.C("casts").Count()

	pers := 6
	pager.Init(pers, num)

	casts := []models.Casts{}
	viewCasts := []models.CastsView{}

	db.C("casts").Find(nil).Limit(pers).Skip(pager.Offset()).All(&casts)

	for _, t := range casts {
		viewCasts = append(viewCasts,
			models.CastsView{Id: t.Id.Hex(),
				Author:     t.Author,
				AuthorUrl:  t.AuthorUrl,
				VisitCount: t.VisitCount,
				Title:      t.Title,
				LogoUrl:    t.LogoUrl,
				Intro:      template.HTML(t.Intro),
				ShowNotes:  template.HTML(t.ShowNotes),
				Url:        t.Url})
	}

	if db.Session != nil {
		defer db.Session.Close()
	}

	r.HTML(200, "casts", map[string]interface{}{
		"IsCasts":   true,
		"Casts":     viewCasts,
		"Paginator": pager,
		"Num":       num})
}
Ejemplo n.º 29
0
func AdminUpdatePassword(req *http.Request, r render.Render, db *mgo.Database) {
	pass := req.FormValue("password")
	verify := req.FormValue("verify")

	if pass == verify {

		hashedPass, _ := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
		info, err := db.C("id").Upsert(bson.M{"email": "*****@*****.**"}, bson.M{"$set": bson.M{"password": hashedPass, "email": "*****@*****.**"}})

		if err == nil {
			if info.Updated >= 0 {
				r.HTML(200, "admin/password", map[string]interface{}{
					"IsPost":     true,
					"IsPassword": true,
					"IsSuccess":  true}, render.HTMLOptions{Layout: "admin/layout"})
			}
		}
	} else {
		r.HTML(200, "admin/password", map[string]interface{}{
			"IsPost":     true,
			"IsPassword": true,
			"IsSuccess":  false}, render.HTMLOptions{Layout: "admin/layout"})
	}
}
Ejemplo n.º 30
0
func ShowCast(r render.Render, params martini.Params) {
	db := GetDBInstance()
	cast := models.Casts{}

	db.C("casts").FindId(bson.ObjectIdHex(params["Id"])).One(&cast)

	viewCast := models.CastsView{Id: cast.Id.Hex(),
		Author:     cast.Author,
		AuthorUrl:  cast.AuthorUrl,
		VisitCount: cast.VisitCount,
		Title:      cast.Title,
		LogoUrl:    cast.LogoUrl,
		Intro:      template.HTML(cast.Intro),
		ShowNotes:  template.HTML(cast.ShowNotes),
		Url:        cast.Url}

	if db.Session != nil {
		defer db.Session.Close()
	}

	r.HTML(200, "show", map[string]interface{}{
		"IsCasts":  true,
		"ViewCast": viewCast})
}