diff --git a/conf/config.yaml b/conf/config.yaml index 01dc071..62003f6 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -2,6 +2,7 @@ lang: "zh-CN" app: web-client: 1 # 1:启用 0:禁用 register: false #是否开启注册 + register-status: 1 # 注册用户默认状态 1:启用 2:禁用 captcha-threshold: 3 # <0:disabled, 0 always, >0:enabled ban-threshold: 0 # 0:disabled, >0:enabled show-swagger: 0 # 1:启用 0:禁用 diff --git a/config/config.go b/config/config.go index 45030cf..b176d18 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ const ( type App struct { WebClient int `mapstructure:"web-client"` Register bool `mapstructure:"register"` + RegisterStatus int `mapstructure:"register-status"` ShowSwagger int `mapstructure:"show-swagger"` TokenExpire time.Duration `mapstructure:"token-expire"` WebSso bool `mapstructure:"web-sso"` diff --git a/http/controller/admin/user.go b/http/controller/admin/user.go index e593d02..4b29530 100644 --- a/http/controller/admin/user.go +++ b/http/controller/admin/user.go @@ -320,11 +320,22 @@ func (ct *User) Register(c *gin.Context) { response.Fail(c, 101, errList[0]) return } - u := service.AllService.UserService.Register(f.Username, f.Email, f.Password) + regStatus := model.StatusCode(global.Config.App.RegisterStatus) + // 注册状态可能未配置,默认启用 + if regStatus != model.COMMON_STATUS_DISABLED && regStatus != model.COMMON_STATUS_ENABLE { + regStatus = model.COMMON_STATUS_ENABLE + } + + u := service.AllService.UserService.Register(f.Username, f.Email, f.Password, regStatus) if u == nil || u.Id == 0 { response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")) return } + if regStatus == model.COMMON_STATUS_DISABLED { + // 需要管理员审核 + response.Fail(c, 101, response.TranslateMsg(c, "RegisterSuccessWaitAdminConfirm")) + return + } // 注册成功后自动登录 ut := service.AllService.UserService.Login(u, &model.LoginLog{ UserId: u.Id, diff --git a/resources/i18n/en.toml b/resources/i18n/en.toml index 8cea201..2c64f9f 100644 --- a/resources/i18n/en.toml +++ b/resources/i18n/en.toml @@ -147,4 +147,9 @@ other = "Cannot share to self." [Banned] description = "Banned." one = "Banned." -other = "Banned." \ No newline at end of file +other = "Banned." + +[RegisterSuccessWaitAdminConfirm] +description = "Register success, wait admin confirm." +one = "Register success, wait admin confirm." +other = "Register success, wait admin confirm." \ No newline at end of file diff --git a/resources/i18n/es.toml b/resources/i18n/es.toml index 3bcff6f..efbba84 100644 --- a/resources/i18n/es.toml +++ b/resources/i18n/es.toml @@ -156,4 +156,9 @@ other = "No se puede compartir con uno mismo." [Banned] description = "Banned." one = "Prohibido." -other = "Prohibido." \ No newline at end of file +other = "Prohibido." + +[RegisterSuccessWaitAdminConfirm] +description = "Register success, wait admin confirm." +one = "Registro exitoso, espere la confirmación del administrador." +other = "Registro exitoso, espere la confirmación del administrador." \ No newline at end of file diff --git a/resources/i18n/fr.toml b/resources/i18n/fr.toml index 093f738..78906f4 100644 --- a/resources/i18n/fr.toml +++ b/resources/i18n/fr.toml @@ -156,4 +156,9 @@ other = "Impossible de partager avec soi-même." [Banned] description = "Banned." one = "Banni." -other = "Banni." \ No newline at end of file +other = "Banni." + +[RegisterSuccessWaitAdminConfirm] +description = "Register success wait admin confirm." +one = "Inscription réussie, veuillez attendre la confirmation de l'administrateur." +other = "Inscription réussie, veuillez attendre la confirmation de l'administrateur." \ No newline at end of file diff --git a/resources/i18n/ko.toml b/resources/i18n/ko.toml index 1667c1a..16d2bed 100644 --- a/resources/i18n/ko.toml +++ b/resources/i18n/ko.toml @@ -150,4 +150,9 @@ other = "자기 자신에게 공유할 수 없습니다." [Banned] description = "Banned." one = "금지됨." -other = "금지됨." \ No newline at end of file +other = "금지됨." + +[RegisterSuccessWaitAdminConfirm] +description = "Register success wait admin confirm." +one = "가입 성공, 관리자 확인 대기 중." +other = "가입 성공, 관리자 확인 대기 중." \ No newline at end of file diff --git a/resources/i18n/ru.toml b/resources/i18n/ru.toml index 05a0e31..c7da252 100644 --- a/resources/i18n/ru.toml +++ b/resources/i18n/ru.toml @@ -156,4 +156,9 @@ other = "Нельзя поделиться с собой." [Banned] description = "Banned." one = "Заблокировано." -other = "Заблокировано." \ No newline at end of file +other = "Заблокировано." + +[RegisterSuccessWaitAdminConfirm] +description = "Register success wait admin confirm." +one = "Регистрация прошла успешно, ожидайте подтверждения администратора." +other = "Регистрация прошла успешно, ожидайте подтверждения администратора." \ No newline at end of file diff --git a/resources/i18n/zh_CN.toml b/resources/i18n/zh_CN.toml index 6403d03..bd86383 100644 --- a/resources/i18n/zh_CN.toml +++ b/resources/i18n/zh_CN.toml @@ -149,4 +149,9 @@ other = "不能共享给自己。" [Banned] description = "Banned." one = "已被封禁。" -other = "已被封禁。" \ No newline at end of file +other = "已被封禁。" + +[RegisterSuccessWaitAdminConfirm] +description = "Register success, wait for admin confirm." +one = "注册成功,请等待管理员审核。" +other = "注册成功,请等待管理员审核。" \ No newline at end of file diff --git a/resources/i18n/zh_TW.toml b/resources/i18n/zh_TW.toml index 2197535..8821412 100644 --- a/resources/i18n/zh_TW.toml +++ b/resources/i18n/zh_TW.toml @@ -149,4 +149,9 @@ other = "無法共享給自己。" [Banned] description = "Banned." one = "禁止使用。" -other = "禁止使用。" \ No newline at end of file +other = "禁止使用。" + +[RegisterSuccessWaitAdminConfirm] +description = "Register success wait admin confirm." +one = "註冊成功,請等待管理員確認。" +other = "註冊成功,請等待管理員確認。" \ No newline at end of file diff --git a/service/user.go b/service/user.go index 6a35033..aca25e9 100644 --- a/service/user.go +++ b/service/user.go @@ -412,12 +412,13 @@ func (us *UserService) IsPasswordEmptyByUser(u *model.User) bool { } // Register 注册, 如果用户名已存在则返回nil -func (us *UserService) Register(username string, email string, password string) *model.User { +func (us *UserService) Register(username string, email string, password string, status model.StatusCode) *model.User { u := &model.User{ Username: username, Email: email, Password: password, GroupId: 1, + Status: status, } err := us.Create(u) if err != nil {