Exemplo n.º 1
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")
	}
}
Exemplo n.º 2
0
func Contexter(c martini.Context, r render.Render, sess sessions.Session, req *http.Request) {
	email := sess.Get("email")
	var user *common.User

	if email != nil {
		user, _ = common.FindCachedUser(email.(string))
	} else {
		user = nil
	}

	ctx := &Context{
		Session: sess,
		IsGuest: user == nil,
		User:    user,
		Request: req,
		Render:  r,
	}
	c.Map(ctx)
}