New parameter to display a message at the top of the screen

This commit is contained in:
nemunaire 2023-03-07 02:53:47 +01:00
parent f7da603dbe
commit b604e98f64
3 changed files with 15 additions and 6 deletions

15
auth.go
View file

@ -13,6 +13,7 @@ import (
var LocalAuthFunc = checkAuthKrb5
var allowLocalAuth bool
var localAuthUsers arrayFlags
var mainBanner string
type loginForm struct {
Login string `json:"username"`
@ -47,16 +48,18 @@ func declareAPIAdminAuthRoutes(router *gin.RouterGroup) {
session.Update()
c.JSON(http.StatusOK, authToken{
User: newuser,
CurrentPromo: currentPromo,
User: newuser,
CurrentPromo: currentPromo,
MessageBanner: mainBanner,
})
})
}
type authToken struct {
*User
CurrentPromo uint `json:"current_promo"`
Groups []string `json:"groups"`
CurrentPromo uint `json:"current_promo"`
Groups []string `json:"groups"`
MessageBanner string `json:"banner,omitempty"`
}
func validateAuthToken(c *gin.Context) {
@ -64,7 +67,7 @@ func validateAuthToken(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Not connected"})
return
} else {
t := authToken{User: u.(*User), CurrentPromo: currentPromo}
t := authToken{User: u.(*User), CurrentPromo: currentPromo, MessageBanner: mainBanner}
t.Groups = strings.Split(strings.TrimFunc(t.User.Groups, func(r rune) bool { return !unicode.IsLetter(r) }), ",")
@ -157,6 +160,6 @@ func dummyAuth(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": err.Error()})
return
} else {
c.JSON(http.StatusOK, authToken{User: usr, CurrentPromo: currentPromo})
c.JSON(http.StatusOK, authToken{User: usr, CurrentPromo: currentPromo, MessageBanner: mainBanner})
}
}