From 17b287972fe2aab06f8cb328bb956f440c4ba15a Mon Sep 17 00:00:00 2001 From: okatu-loli Date: Mon, 18 Aug 2025 13:13:46 +0800 Subject: [PATCH] feat(register-and-statistics): add user registration endpoint (#register-and-statistics) - Added `POST /auth/register` endpoint to support user registration. - Implemented registration logic in `auth.go` with dynamic role assignment. - Integrated `AllowRegister` and `DefaultRole` settings for registration flow. - Updated imports to include new modules: `conf`, `setting`. - Adjusted user creation logic to use `DefaultRole` dynamically. --- server/handles/user.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/handles/user.go b/server/handles/user.go index b4c152c5..922b7f67 100644 --- a/server/handles/user.go +++ b/server/handles/user.go @@ -4,8 +4,10 @@ import ( "github.com/alist-org/alist/v3/pkg/utils" "strconv" + "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/op" + "github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" @@ -36,6 +38,9 @@ func CreateUser(c *gin.Context) { common.ErrorResp(c, err, 400) return } + if len(req.Role) == 0 { + req.Role = model.Roles{setting.GetInt(conf.DefaultRole, int(model.GUEST))} + } if req.IsAdmin() || req.IsGuest() { common.ErrorStrResp(c, "admin or guest user can not be created", 400, true) return