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})
}
}

View File

@ -58,6 +58,7 @@ func main() {
var bind = flag.String("bind", ":8081", "Bind port/socket")
var dsn = flag.String("dsn", DSNGenerator(), "DSN to connect to the MySQL server")
var dummyauth = flag.Bool("dummy-auth", false, "If set, allow any authentication credentials")
flag.StringVar(&mainBanner, "banner-message", mainBanner, "Display a message to connected user, at the top of the screen")
flag.StringVar(&DevProxy, "dev", DevProxy, "Proxify traffic to this host for static assets")
flag.StringVar(&baseURL, "baseurl", baseURL, "URL prepended to each URL")
flag.UintVar(&currentPromo, "current-promo", currentPromo, "Year of the current promotion")

View File

@ -29,6 +29,11 @@
<title>ЕРІТА: MCQ and others courses related stuff</title>
</svelte:head>
{#if $user && $user.banner}
<div class="bg-danger text-white text-center py-1 fw-bolder">
{$user.banner}
</div>
{/if}
{#if isSRS}
<div style="position: fixed; bottom: 20px; right: 20px; z-index: -1; background-image: url('img/srstamps.png'); background-size: cover; width: 125px; height: 125px;"></div>
{/if}