Browse Source

feat(register): Register status can be set (#223)

lejianwen 8 months ago
parent
commit
d4fdf3785b

+ 1 - 0
conf/config.yaml

@@ -2,6 +2,7 @@ lang: "zh-CN"
2 2
 app:
3 3
   web-client: 1  # 1:启用 0:禁用
4 4
   register: false #是否开启注册
5
+  register-status: 1 # 注册用户默认状态 1:启用 2:禁用
5 6
   captcha-threshold: 3 #   <0:disabled, 0 always, >0:enabled
6 7
   ban-threshold: 0 # 0:disabled, >0:enabled
7 8
   show-swagger: 0 # 1:启用 0:禁用

+ 1 - 0
config/config.go

@@ -16,6 +16,7 @@ const (
16 16
 type App struct {
17 17
 	WebClient        int           `mapstructure:"web-client"`
18 18
 	Register         bool          `mapstructure:"register"`
19
+	RegisterStatus   int           `mapstructure:"register-status"`
19 20
 	ShowSwagger      int           `mapstructure:"show-swagger"`
20 21
 	TokenExpire      time.Duration `mapstructure:"token-expire"`
21 22
 	WebSso           bool          `mapstructure:"web-sso"`

+ 12 - 1
http/controller/admin/user.go

@@ -320,11 +320,22 @@ func (ct *User) Register(c *gin.Context) {
320 320
 		response.Fail(c, 101, errList[0])
321 321
 		return
322 322
 	}
323
-	u := service.AllService.UserService.Register(f.Username, f.Email, f.Password)
323
+	regStatus := model.StatusCode(global.Config.App.RegisterStatus)
324
+	// 注册状态可能未配置,默认启用
325
+	if regStatus != model.COMMON_STATUS_DISABLED && regStatus != model.COMMON_STATUS_ENABLE {
326
+		regStatus = model.COMMON_STATUS_ENABLE
327
+	}
328
+
329
+	u := service.AllService.UserService.Register(f.Username, f.Email, f.Password, regStatus)
324 330
 	if u == nil || u.Id == 0 {
325 331
 		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed"))
326 332
 		return
327 333
 	}
334
+	if regStatus == model.COMMON_STATUS_DISABLED {
335
+		// 需要管理员审核
336
+		response.Fail(c, 101, response.TranslateMsg(c, "RegisterSuccessWaitAdminConfirm"))
337
+		return
338
+	}
328 339
 	// 注册成功后自动登录
329 340
 	ut := service.AllService.UserService.Login(u, &model.LoginLog{
330 341
 		UserId: u.Id,

+ 6 - 1
resources/i18n/en.toml

@@ -147,4 +147,9 @@ other = "Cannot share to self."
147 147
 [Banned]
148 148
 description = "Banned."
149 149
 one = "Banned."
150
-other = "Banned."
150
+other = "Banned."
151
+
152
+[RegisterSuccessWaitAdminConfirm]
153
+description = "Register success, wait admin confirm."
154
+one = "Register success, wait admin confirm."
155
+other = "Register success, wait admin confirm."

+ 6 - 1
resources/i18n/es.toml

@@ -156,4 +156,9 @@ other = "No se puede compartir con uno mismo."
156 156
 [Banned]
157 157
 description = "Banned."
158 158
 one = "Prohibido."
159
-other = "Prohibido."
159
+other = "Prohibido."
160
+
161
+[RegisterSuccessWaitAdminConfirm]
162
+description = "Register success, wait admin confirm."
163
+one = "Registro exitoso, espere la confirmación del administrador."
164
+other = "Registro exitoso, espere la confirmación del administrador."

+ 6 - 1
resources/i18n/fr.toml

@@ -156,4 +156,9 @@ other = "Impossible de partager avec soi-même."
156 156
 [Banned]
157 157
 description = "Banned."
158 158
 one = "Banni."
159
-other = "Banni."
159
+other = "Banni."
160
+
161
+[RegisterSuccessWaitAdminConfirm]
162
+description = "Register success wait admin confirm."
163
+one = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."
164
+other = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."

+ 6 - 1
resources/i18n/ko.toml

@@ -150,4 +150,9 @@ other = "자기 자신에게 공유할 수 없습니다."
150 150
 [Banned]
151 151
 description = "Banned."
152 152
 one = "금지됨."
153
-other = "금지됨."
153
+other = "금지됨."
154
+
155
+[RegisterSuccessWaitAdminConfirm]
156
+description = "Register success wait admin confirm."
157
+one = "가입 성공, 관리자 확인 대기 중."
158
+other = "가입 성공, 관리자 확인 대기 중."

+ 6 - 1
resources/i18n/ru.toml

@@ -156,4 +156,9 @@ other = "Нельзя поделиться с собой."
156 156
 [Banned]
157 157
 description = "Banned."
158 158
 one = "Заблокировано."
159
-other = "Заблокировано."
159
+other = "Заблокировано."
160
+
161
+[RegisterSuccessWaitAdminConfirm]
162
+description = "Register success wait admin confirm."
163
+one = "Регистрация прошла успешно, ожидайте подтверждения администратора."
164
+other = "Регистрация прошла успешно, ожидайте подтверждения администратора."

+ 6 - 1
resources/i18n/zh_CN.toml

@@ -149,4 +149,9 @@ other = "不能共享给自己。"
149 149
 [Banned]
150 150
 description = "Banned."
151 151
 one = "已被封禁。"
152
-other = "已被封禁。"
152
+other = "已被封禁。"
153
+
154
+[RegisterSuccessWaitAdminConfirm]
155
+description = "Register success, wait for admin confirm."
156
+one = "注册成功,请等待管理员审核。"
157
+other = "注册成功,请等待管理员审核。"

+ 6 - 1
resources/i18n/zh_TW.toml

@@ -149,4 +149,9 @@ other = "無法共享給自己。"
149 149
 [Banned]
150 150
 description = "Banned."
151 151
 one = "禁止使用。"
152
-other = "禁止使用。"
152
+other = "禁止使用。"
153
+
154
+[RegisterSuccessWaitAdminConfirm]
155
+description = "Register success wait admin confirm."
156
+one = "註冊成功,請等待管理員確認。"
157
+other = "註冊成功,請等待管理員確認。"

+ 2 - 1
service/user.go

@@ -412,12 +412,13 @@ func (us *UserService) IsPasswordEmptyByUser(u *model.User) bool {
412 412
 }
413 413
 
414 414
 // Register 注册, 如果用户名已存在则返回nil
415
-func (us *UserService) Register(username string, email string, password string) *model.User {
415
+func (us *UserService) Register(username string, email string, password string, status model.StatusCode) *model.User {
416 416
 	u := &model.User{
417 417
 		Username: username,
418 418
 		Email:    email,
419 419
 		Password: password,
420 420
 		GroupId:  1,
421
+		Status:   status,
421 422
 	}
422 423
 	err := us.Create(u)
423 424
 	if err != nil {