The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/api/api_auth.go

49 lines
996 B

package api
import (
"github.com/gin-gonic/gin"
"github.com/torkelo/grafana-pro/pkg/models"
)
type authContext struct {
11 years ago
account *models.Account
userAccount *models.Account
}
func (auth *authContext) getAccountId() int {
return auth.account.Id
}
func (self *HttpServer) authDenied(c *gin.Context) {
c.Writer.Header().Set("Location", "/login")
c.Abort(302)
}
func (self *HttpServer) auth() gin.HandlerFunc {
return func(c *gin.Context) {
session, _ := sessionStore.Get(c.Request, "grafana-session")
if c.Request.URL.Path != "/login" && session.Values["accountId"] == nil {
self.authDenied(c)
return
}
account, err := self.store.GetAccount(session.Values["accountId"].(int))
if err != nil {
self.authDenied(c)
return
}
usingAccount, err := self.store.GetAccount(account.UsingAccountId)
if err != nil {
self.authDenied(c)
return
}
c.Set("userAccount", account)
c.Set("usingAccount", usingAccount)
session.Save(c.Request, c.Writer)
}
}