added setting to turn off login/edits - LOGIN_AND_EDITS

This commit is contained in:
2026-04-23 06:19:45 +00:00
parent 3c70cb99a3
commit a30eb4d42d
6 changed files with 33 additions and 6 deletions
+12
View File
@@ -13,6 +13,18 @@ import (
const csrfSessionKey = "csrf_token"
// RequireLoginAndEdits blocks access if LoginAndEdits setting is false.
func (s *Server) RequireLoginAndEdits() gin.HandlerFunc {
return func(c *gin.Context) {
if !s.config.LoginAndEdits {
c.Redirect(http.StatusFound, s.config.URLPrefix+"/?error=not_found")
c.Abort()
return
}
c.Next()
}
}
func (s *Server) randomToken(n int) (string, error) {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {