Exemple #1
0
func validateSession(r render.Render, s sessions.Session) {
	isLogin := s.Get("IsLogin")

	if isLogin == nil {
		fmt.Println("Not login...")
		r.Redirect("/admin/login")
	}
}
Exemple #2
0
func AdminAddTips(req *http.Request, r render.Render, db *mgo.Database) {
	content := req.FormValue("tip")
	comment := req.FormValue("comment")

	tip := models.Tips{Id: bson.NewObjectId(), Content: content, Comment: comment}
	db.C("tips").Insert(tip)

	r.Redirect("/admin/tips")
}
Exemple #3
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{})
}
Exemple #4
0
func AdminAddCasts(req *http.Request, r render.Render, db *mgo.Database) {
	author := req.FormValue("author")
	aurhor_url := req.FormValue("authorurl")
	title := req.FormValue("title")
	intro := req.FormValue("intro")
	show_notes := req.FormValue("shownotes")
	url := req.FormValue("url")
	logo_url := req.FormValue("logourl")

	cast := models.Casts{Id: bson.NewObjectId(), Author: author, AuthorUrl: aurhor_url,
		VisitCount: 0, Title: title, Intro: intro, ShowNotes: show_notes, Url: url, LogoUrl: logo_url}
	db.C("casts").Insert(cast)

	r.Redirect("/admin/casts")
}
Exemple #5
0
func issueRedirectHandler(render render.Render, r *http.Request, params martini.Params) {
	organization := params["org"]
	repo := params["repo"]
	issueID := params["issue_id"]

	url := fmt.Sprintf("https://github.com/%s/%s/issues/%s", organization, repo, issueID)
	render.Redirect(url)
}
Exemple #6
0
func prRedirectHandler(render render.Render, r *http.Request, params martini.Params) {
	organization := params["org"]
	repo := params["repo"]
	pullRequestID := params["pull_id"]

	url := fmt.Sprintf("https://github.com/%s/%s/pull/%s", organization, repo, pullRequestID)
	render.Redirect(url)
}
Exemple #7
0
func AdminUpdateCasts(r render.Render, db *mgo.Database, req *http.Request) {
	author := req.FormValue("author")
	author_url := req.FormValue("authorurl")
	title := req.FormValue("title")
	intro := req.FormValue("intro")
	show_notes := req.FormValue("shownotes")
	url := req.FormValue("url")
	logo_url := req.FormValue("logourl")

	db.C("casts").UpdateId(bson.ObjectIdHex(req.FormValue("id")),
		bson.M{"$set": bson.M{"author": author,
			"authorurl": author_url,
			"title":     title,
			"intro":     intro,
			"shownotes": show_notes,
			"url":       url,
			"logourl":   logo_url}})

	r.Redirect("/admin/casts")
}
Exemple #8
0
func HandleLogin(req *http.Request, r render.Render, s sessions.Session, db *mgo.Database) {
	username := req.FormValue("username")
	pass := req.FormValue("password")

	id := models.Identity{}

	err := db.C("id").Find(bson.M{"email": "*****@*****.**"}).One(&id)

	if err != nil {
		fmt.Println(err.Error())
	}

	if username == "*****@*****.**" && bcrypt.CompareHashAndPassword(id.Password, []byte(pass)) == nil {
		fmt.Println("Login success!")
		s.Set("IsLogin", true)

		r.Redirect("/admin/index")
	} else {
		r.Redirect("/admin/login")
	}
}
Exemple #9
0
// Check user authentication
func Authorize(r render.Render, sess sessions.Session) {
	email := sess.Get("email")
	if email != nil {
		user, err := common.FindCachedUser(email.(string))
		if err == common.ErrSendingElasticSearchRequest {
			r.Redirect("/maintenance")
			return
		}
		if user == nil {
			r.Redirect("/login")
			return
		}
	} else {
		r.Redirect("/login")
	}
}
Exemple #10
0
// New - Method for convertation POST DOT plaintext into base64
// and Redirect for rendering
func (dotviz *DotVizController) New(r render.Render, req *http.Request, res http.ResponseWriter) {
	dotString := req.FormValue("text")
	dotBase64 := base64.StdEncoding.EncodeToString([]byte(dotString))
	r.Redirect(fmt.Sprintf("/dotviz/%v", dotBase64))
}
Exemple #11
0
// Redirect user to Dashboard if authorized
func RedirectIfAuthorized(r render.Render, sess sessions.Session) {
	email := sess.Get("email")
	if email != nil {
		r.Redirect("/")
	}
}
Exemple #12
0
func AdminDelTips(req *http.Request, r render.Render, db *mgo.Database) {
	id := req.FormValue("Id")
	db.C("tips").RemoveId(bson.ObjectIdHex(id))

	r.Redirect("/admin/tips")
}
Exemple #13
0
// LoginRequired verifies that the current user is authenticated. Any routes that
// require a login should have this handler placed in the flow. If the user is not
// authenticated, they will be redirected to /login with the "next" get parameter
// set to the attempted URL.
func LoginRequired(r render.Render, user User, req *http.Request) {
	if user.IsAuthenticated() == false {
		path := fmt.Sprintf("/login?next=%s", req.URL.Path)
		r.Redirect(path, 302)
	}
}
Exemple #14
0
func HandleLogout(r render.Render, s sessions.Session) {
	s.Delete("IsLogin")
	r.Redirect("/admin/login")
}