Add config to disable registration

This commit is contained in:
2026-02-24 00:00:35 +01:00
parent 67b305786b
commit 00a5a6c045
7 changed files with 72 additions and 1 deletions

View File

@@ -4,6 +4,8 @@
import NavBarSearch from './NavBarSearch.vue' import NavBarSearch from './NavBarSearch.vue'
import BarcodeModal from './BarcodeModal.vue' import BarcodeModal from './BarcodeModal.vue'
import { useAuthStore } from './auth.store.js' import { useAuthStore } from './auth.store.js'
import { getAppInfo } from './api.js'
import { onMounted } from 'vue'
const authStore = useAuthStore(); const authStore = useAuthStore();
const router = useRouter(); const router = useRouter();
@@ -16,6 +18,12 @@
router.push('/'); router.push('/');
} }
const appInfo = ref(null);
const appInfoErr = ref(null);
onMounted(() => {
getAppInfo(appInfo, appInfoErr);
})
</script> </script>
<template> <template>
@@ -74,7 +82,7 @@
</div> </div>
<div v-else class="navbar-item"> <div v-else class="navbar-item">
<div class="buttons"> <div class="buttons">
<RouterLink to="/signup" class="button is-primary"> <RouterLink v-if="appInfo && !appInfo.registrationDisabled" to="/signup" class="button is-primary">
<strong>{{ $t('navbar.signup')}}</strong> <strong>{{ $t('navbar.signup')}}</strong>
</RouterLink> </RouterLink>
<RouterLink to="/login" class="button is-light"> <RouterLink to="/login" class="button is-light">

View File

@@ -34,6 +34,14 @@ function useFetch(data, error, url) {
} }
} }
export function getAppInfo(appInfo, appInfoErr) {
fetch('/ws/appinfo', {
method: 'GET'
}).then((res) => res.json())
.then((json) => appInfo.value = json)
.catch((err) => (appInfoErr.value = err))
}
export function getMyBooks(data, error, arg, limit, offset) { export function getMyBooks(data, error, arg, limit, offset) {
const queryParams = new URLSearchParams({limit: limit, offset: offset}); const queryParams = new URLSearchParams({limit: limit, offset: offset});
return useFetch(data, error, '/ws/mybooks/' + arg + "?" + queryParams.toString()); return useFetch(data, error, '/ws/mybooks/' + arg + "?" + queryParams.toString());

View File

@@ -0,0 +1,30 @@
package apitest
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"git.artlef.fr/PersonalLibraryManager/internal/dto"
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
"github.com/stretchr/testify/assert"
)
func TestGetAppInfo_Ok(t *testing.T) {
router := testutils.TestSetup()
req, _ := http.NewRequest("GET", "/ws/appinfo", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var appInfo dto.AppInfo
err := json.Unmarshal(w.Body.Bytes(), &appInfo)
if err != nil {
t.Error(err)
}
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, false, appInfo.RegistrationDisabled)
}

View File

@@ -1,5 +1,9 @@
package dto package dto
type AppInfo struct {
RegistrationDisabled bool `json:"registrationDisabled"`
}
type BookGet struct { type BookGet struct {
Title string `json:"title" binding:"required,max=300"` Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"` Author string `json:"author" binding:"max=100"`

View File

@@ -17,6 +17,11 @@ func Auth() gin.HandlerFunc {
return return
} }
//do not check appinfo
if strings.HasPrefix(c.FullPath(), "/ws/appinfo") {
return
}
//do not check static files //do not check static files
if strings.HasPrefix(c.FullPath(), "/static/bookcover/") { if strings.HasPrefix(c.FullPath(), "/static/bookcover/") {
return return

View File

@@ -0,0 +1,12 @@
package routes
import (
"net/http"
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
"git.artlef.fr/PersonalLibraryManager/internal/dto"
)
func GetAppInfo(ac appcontext.AppContext) {
ac.C.JSON(http.StatusOK, dto.AppInfo{RegistrationDisabled: ac.Config.DisableRegistration})
}

View File

@@ -30,6 +30,10 @@ func Setup(config *config.Config) *gin.Engine {
ws := r.Group("/ws") ws := r.Group("/ws")
ws.Use(middleware.Auth()) ws.Use(middleware.Auth())
ws.GET("/appinfo", func(c *gin.Context) {
routes.GetAppInfo(appcontext.AppContext{C: c, Db: db, I18n: bundle, Config: config})
})
ws.GET("/mybooks/read", func(c *gin.Context) { ws.GET("/mybooks/read", func(c *gin.Context) {
routes.GetMyBooksReadHandler(appcontext.AppContext{C: c, Db: db, I18n: bundle, Config: config}) routes.GetMyBooksReadHandler(appcontext.AppContext{C: c, Db: db, I18n: bundle, Config: config})
}) })