Interpret Groups field in authToken
This commit is contained in:
parent
a203cdc36a
commit
46abdc9120
13
auth.go
13
auth.go
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -26,7 +28,8 @@ func declareAPIAuthRoutes(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
type authToken struct {
|
type authToken struct {
|
||||||
*User
|
*User
|
||||||
CurrentPromo uint `json:"current_promo"`
|
CurrentPromo uint `json:"current_promo"`
|
||||||
|
Groups []string `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateAuthToken(c *gin.Context) {
|
func validateAuthToken(c *gin.Context) {
|
||||||
@ -34,7 +37,11 @@ func validateAuthToken(c *gin.Context) {
|
|||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Not connected"})
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Not connected"})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, authToken{u.(*User), currentPromo})
|
t := authToken{User: u.(*User), CurrentPromo: currentPromo}
|
||||||
|
|
||||||
|
t.Groups = strings.Split(strings.TrimFunc(t.User.Groups, func(r rune) bool { return !unicode.IsLetter(r) }), ",")
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +114,6 @@ func dummyAuth(c *gin.Context) {
|
|||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": err.Error()})
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": err.Error()})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, authToken{usr, currentPromo})
|
c.JSON(http.StatusOK, authToken{User: usr, CurrentPromo: currentPromo})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
users.go
2
users.go
@ -111,7 +111,7 @@ type User struct {
|
|||||||
Lastname string `json:"lastname"`
|
Lastname string `json:"lastname"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Promo uint `json:"promo"`
|
Promo uint `json:"promo"`
|
||||||
Groups string `json:"groups"`
|
Groups string `json:"groups,omitempty"`
|
||||||
IsAdmin bool `json:"is_admin"`
|
IsAdmin bool `json:"is_admin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user