feat(register): Register status can be set (#223)
This commit is contained in:
@@ -2,6 +2,7 @@ lang: "zh-CN"
|
|||||||
app:
|
app:
|
||||||
web-client: 1 # 1:启用 0:禁用
|
web-client: 1 # 1:启用 0:禁用
|
||||||
register: false #是否开启注册
|
register: false #是否开启注册
|
||||||
|
register-status: 1 # 注册用户默认状态 1:启用 2:禁用
|
||||||
captcha-threshold: 3 # <0:disabled, 0 always, >0:enabled
|
captcha-threshold: 3 # <0:disabled, 0 always, >0:enabled
|
||||||
ban-threshold: 0 # 0:disabled, >0:enabled
|
ban-threshold: 0 # 0:disabled, >0:enabled
|
||||||
show-swagger: 0 # 1:启用 0:禁用
|
show-swagger: 0 # 1:启用 0:禁用
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const (
|
|||||||
type App struct {
|
type App struct {
|
||||||
WebClient int `mapstructure:"web-client"`
|
WebClient int `mapstructure:"web-client"`
|
||||||
Register bool `mapstructure:"register"`
|
Register bool `mapstructure:"register"`
|
||||||
|
RegisterStatus int `mapstructure:"register-status"`
|
||||||
ShowSwagger int `mapstructure:"show-swagger"`
|
ShowSwagger int `mapstructure:"show-swagger"`
|
||||||
TokenExpire time.Duration `mapstructure:"token-expire"`
|
TokenExpire time.Duration `mapstructure:"token-expire"`
|
||||||
WebSso bool `mapstructure:"web-sso"`
|
WebSso bool `mapstructure:"web-sso"`
|
||||||
|
|||||||
@@ -320,11 +320,22 @@ func (ct *User) Register(c *gin.Context) {
|
|||||||
response.Fail(c, 101, errList[0])
|
response.Fail(c, 101, errList[0])
|
||||||
return
|
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 {
|
if u == nil || u.Id == 0 {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed"))
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if regStatus == model.COMMON_STATUS_DISABLED {
|
||||||
|
// 需要管理员审核
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "RegisterSuccessWaitAdminConfirm"))
|
||||||
|
return
|
||||||
|
}
|
||||||
// 注册成功后自动登录
|
// 注册成功后自动登录
|
||||||
ut := service.AllService.UserService.Login(u, &model.LoginLog{
|
ut := service.AllService.UserService.Login(u, &model.LoginLog{
|
||||||
UserId: u.Id,
|
UserId: u.Id,
|
||||||
|
|||||||
@@ -147,4 +147,9 @@ other = "Cannot share to self."
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "Banned."
|
one = "Banned."
|
||||||
other = "Banned."
|
other = "Banned."
|
||||||
|
|
||||||
|
[RegisterSuccessWaitAdminConfirm]
|
||||||
|
description = "Register success, wait admin confirm."
|
||||||
|
one = "Register success, wait admin confirm."
|
||||||
|
other = "Register success, wait admin confirm."
|
||||||
@@ -156,4 +156,9 @@ other = "No se puede compartir con uno mismo."
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "Prohibido."
|
one = "Prohibido."
|
||||||
other = "Prohibido."
|
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."
|
||||||
@@ -156,4 +156,9 @@ other = "Impossible de partager avec soi-même."
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "Banni."
|
one = "Banni."
|
||||||
other = "Banni."
|
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."
|
||||||
@@ -150,4 +150,9 @@ other = "자기 자신에게 공유할 수 없습니다."
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "금지됨."
|
one = "금지됨."
|
||||||
other = "금지됨."
|
other = "금지됨."
|
||||||
|
|
||||||
|
[RegisterSuccessWaitAdminConfirm]
|
||||||
|
description = "Register success wait admin confirm."
|
||||||
|
one = "가입 성공, 관리자 확인 대기 중."
|
||||||
|
other = "가입 성공, 관리자 확인 대기 중."
|
||||||
@@ -156,4 +156,9 @@ other = "Нельзя поделиться с собой."
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "Заблокировано."
|
one = "Заблокировано."
|
||||||
other = "Заблокировано."
|
other = "Заблокировано."
|
||||||
|
|
||||||
|
[RegisterSuccessWaitAdminConfirm]
|
||||||
|
description = "Register success wait admin confirm."
|
||||||
|
one = "Регистрация прошла успешно, ожидайте подтверждения администратора."
|
||||||
|
other = "Регистрация прошла успешно, ожидайте подтверждения администратора."
|
||||||
@@ -149,4 +149,9 @@ other = "不能共享给自己。"
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "已被封禁。"
|
one = "已被封禁。"
|
||||||
other = "已被封禁。"
|
other = "已被封禁。"
|
||||||
|
|
||||||
|
[RegisterSuccessWaitAdminConfirm]
|
||||||
|
description = "Register success, wait for admin confirm."
|
||||||
|
one = "注册成功,请等待管理员审核。"
|
||||||
|
other = "注册成功,请等待管理员审核。"
|
||||||
@@ -149,4 +149,9 @@ other = "無法共享給自己。"
|
|||||||
[Banned]
|
[Banned]
|
||||||
description = "Banned."
|
description = "Banned."
|
||||||
one = "禁止使用。"
|
one = "禁止使用。"
|
||||||
other = "禁止使用。"
|
other = "禁止使用。"
|
||||||
|
|
||||||
|
[RegisterSuccessWaitAdminConfirm]
|
||||||
|
description = "Register success wait admin confirm."
|
||||||
|
one = "註冊成功,請等待管理員確認。"
|
||||||
|
other = "註冊成功,請等待管理員確認。"
|
||||||
+2
-1
@@ -412,12 +412,13 @@ func (us *UserService) IsPasswordEmptyByUser(u *model.User) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register 注册, 如果用户名已存在则返回nil
|
// 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{
|
u := &model.User{
|
||||||
Username: username,
|
Username: username,
|
||||||
Email: email,
|
Email: email,
|
||||||
Password: password,
|
Password: password,
|
||||||
GroupId: 1,
|
GroupId: 1,
|
||||||
|
Status: status,
|
||||||
}
|
}
|
||||||
err := us.Create(u)
|
err := us.Create(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user