Interpret Groups field in authToken
This commit is contained in:
parent
a203cdc36a
commit
46abdc9120
11
auth.go
11
auth.go
@ -3,7 +3,9 @@ package main
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -27,6 +29,7 @@ func declareAPIAuthRoutes(router *gin.RouterGroup) {
|
||||
type authToken struct {
|
||||
*User
|
||||
CurrentPromo uint `json:"current_promo"`
|
||||
Groups []string `json:"groups"`
|
||||
}
|
||||
|
||||
func validateAuthToken(c *gin.Context) {
|
||||
@ -34,7 +37,11 @@ func validateAuthToken(c *gin.Context) {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Not connected"})
|
||||
return
|
||||
} 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()})
|
||||
return
|
||||
} else {
|
||||
c.JSON(http.StatusOK, authToken{usr, currentPromo})
|
||||
c.JSON(http.StatusOK, authToken{User: usr, CurrentPromo: currentPromo})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user