Working on login user name state

This commit is contained in:
Torkel Ödegaard
2014-09-17 15:25:07 +02:00
parent ecafc7bf8f
commit 4dfe8b6f69
5 changed files with 38 additions and 12 deletions
+7 -1
View File
@@ -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 {
+7 -3
View File
@@ -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)
}
+11 -2
View File
@@ -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 {