From 4dfe8b6f691d0fe26dedbe22b2372da278c9e2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 17 Sep 2014 15:25:07 +0200 Subject: [PATCH] Working on login user name state --- grafana | 2 +- pkg/api/api.go | 8 +++++++- pkg/api/api_login.go | 10 +++++++--- pkg/api/api_models.go | 13 +++++++++++-- views/index.html | 17 ++++++++++++----- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/grafana b/grafana index 4b382e0faff..4f798cfe568 160000 --- a/grafana +++ b/grafana @@ -1 +1 @@ -Subproject commit 4b382e0faff3fa2e5c05ca3306d54d8e5f8ca89c +Subproject commit 4f798cfe568db2491fe5eea3f06ddd3027117e90 diff --git a/pkg/api/api.go b/pkg/api/api.go index 59c5079dde1..50c07f9bcd5 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -58,7 +58,13 @@ func (self *HttpServer) ListenAndServe() { } func (self *HttpServer) index(c *gin.Context) { - c.HTML(200, "index.html", &indexViewModel{title: "hello from go"}) + viewModel := &IndexDto{} + login, _ := c.Get("login") + if login != nil { + viewModel.User.Login = login.(string) + } + + c.HTML(200, "index.html", viewModel) } func CacheHeadersMiddleware() gin.HandlerFunc { diff --git a/pkg/api/api_login.go b/pkg/api/api_login.go index 275dbc27ac1..67b47552812 100644 --- a/pkg/api/api_login.go +++ b/pkg/api/api_login.go @@ -35,12 +35,15 @@ func (self *HttpServer) loginPost(c *gin.Context) { } session, _ := sessionStore.Get(c.Request, "grafana-session") - session.Values["login"] = true + session.Values["login"] = loginModel.Email session.Values["accountId"] = account.DatabaseId - session.Save(c.Request, c.Writer) - c.JSON(200, gin.H{"status": "you are logged in"}) + var resp = &LoginResultDto{} + resp.Status = "Logged in" + resp.User.Login = account.Login + + c.JSON(200, resp) } func (self *HttpServer) logoutPost(c *gin.Context) { @@ -73,6 +76,7 @@ func (self *HttpServer) auth() gin.HandlerFunc { } c.Set("accountId", session.Values["accountId"]) + c.Set("login", session.Values["login"]) session.Save(c.Request, c.Writer) } diff --git a/pkg/api/api_models.go b/pkg/api/api_models.go index f53d8cd0f4b..22b5d5bb669 100644 --- a/pkg/api/api_models.go +++ b/pkg/api/api_models.go @@ -10,8 +10,17 @@ type errorResponse struct { Message string `json:"message"` } -type indexViewModel struct { - title string +type IndexDto struct { + User CurrentUserDto +} + +type CurrentUserDto struct { + Login string `json:"login"` +} + +type LoginResultDto struct { + Status string `json:"status"` + User CurrentUserDto `json:"user"` } func newErrorResponse(message string) *errorResponse { diff --git a/views/index.html b/views/index.html index 069d5b0c6e2..9f5f83dbae5 100644 --- a/views/index.html +++ b/views/index.html @@ -1,6 +1,5 @@ - - + @@ -8,6 +7,7 @@ Grafana + @@ -20,12 +20,11 @@ - -
+
-
+ +