Create admin settings and moved signup disable setting there
هذا الالتزام موجود في:
@@ -182,3 +182,16 @@ func adminSyncReposFromDB(ctx echo.Context) error {
|
||||
}()
|
||||
return redirect(ctx, "/admin-panel")
|
||||
}
|
||||
|
||||
func adminSetSetting(ctx echo.Context) error {
|
||||
key := ctx.FormValue("key")
|
||||
value := ctx.FormValue("value")
|
||||
|
||||
if err := models.UpdateSetting(key, value); err != nil {
|
||||
return errorRes(500, "Cannot set setting", err)
|
||||
}
|
||||
|
||||
return ctx.JSON(200, map[string]interface{}{
|
||||
"success": true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gorm.io/gorm"
|
||||
"opengist/internal/config"
|
||||
"opengist/internal/models"
|
||||
)
|
||||
|
||||
@@ -16,7 +15,7 @@ func register(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func processRegister(ctx echo.Context) error {
|
||||
if config.C.DisableSignup {
|
||||
if getData(ctx, "signupDisabled") == true {
|
||||
return errorRes(403, "Signing up is disabled", nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ func Start() {
|
||||
g2.POST("/gists/:gist/delete", adminGistDelete)
|
||||
g2.POST("/sync-fs", adminSyncReposFromFS)
|
||||
g2.POST("/sync-db", adminSyncReposFromDB)
|
||||
g2.PUT("/set-setting", adminSetSetting)
|
||||
}
|
||||
|
||||
g1.GET("/all", allGists)
|
||||
@@ -236,7 +237,12 @@ func dataInit(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
ctxValue := context.WithValue(ctx.Request().Context(), "data", echo.Map{})
|
||||
ctx.SetRequest(ctx.Request().WithContext(ctxValue))
|
||||
setData(ctx, "loadStartTime", time.Now())
|
||||
setData(ctx, "signupDisabled", config.C.DisableSignup)
|
||||
|
||||
disableSignup, err := models.GetSetting(models.SettingDisableSignup)
|
||||
if err != nil {
|
||||
return errorRes(500, "Cannot read setting from database", err)
|
||||
}
|
||||
setData(ctx, "signupDisabled", disableSignup == "1")
|
||||
|
||||
return next(ctx)
|
||||
}
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم