Skip to content

Commit d7c67a9

Browse files
Jiri Vlasak6543a1012112796lunny
authored
Manually approve new registration (#13083)
* Add register manual confirm settings option The new settings option is used when manually approving new registrations. * Enable manual confirmation of new registered user When manual registration confirmation is desired (by default `false`) create new user in the database that is *not active*. The user must then be activated manually. This change speeds up the process of adding new confirmed users for Gitea instances without external auth mechanism. (Currently the option is to manually create new user by admin.) * Update docs/content/doc/advanced/config-cheat-sheet.zh-cn.md Co-authored-by: a1012112796 <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: a1012112796 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 36bd5d7 commit d7c67a9

File tree

10 files changed

+18
-2
lines changed

10 files changed

+18
-2
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ ACTIVE_CODE_LIVE_MINUTES = 180
597597
RESET_PASSWD_CODE_LIVE_MINUTES = 180
598598
; Whether a new user needs to confirm their email when registering.
599599
REGISTER_EMAIL_CONFIRM = false
600+
; Whether a new user needs to be confirmed manually after registration. (Requires `REGISTER_EMAIL_CONFIRM` to be disabled.)
601+
REGISTER_MANUAL_CONFIRM = false
600602
; List of domain names that are allowed to be used to register on a Gitea instance
601603
; gitea.io,example.com
602604
EMAIL_DOMAIN_WHITELIST =

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ relation to port exhaustion.
422422
process.
423423
- `REGISTER_EMAIL_CONFIRM`: **false**: Enable this to ask for mail confirmation of registration.
424424
Requires `Mailer` to be enabled.
425+
- `REGISTER_MANUAL_CONFIRM`: **false**: Enable this to manually confirm new registrations.
426+
Requires `REGISTER_EMAIL_CONFIRM` to be disabled.
425427
- `DISABLE_REGISTRATION`: **false**: Disable registration, after which only admin can create
426428
accounts for users.
427429
- `REQUIRE_EXTERNAL_REGISTRATION_PASSWORD`: **false**: Enable this to force externally created

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ menu:
124124
- `ACTIVE_CODE_LIVE_MINUTES`: 登录验证码失效时间,单位分钟。
125125
- `RESET_PASSWD_CODE_LIVE_MINUTES`: 重置密码失效时间,单位分钟。
126126
- `REGISTER_EMAIL_CONFIRM`: 启用注册邮件激活,前提是 `Mailer` 已经启用。
127+
- `REGISTER_MANUAL_CONFIRM`: **false**: 新注册用户必须由管理员手动激活,启用此选项需取消`REGISTER_EMAIL_CONFIRM`.
127128
- `DISABLE_REGISTRATION`: 禁用注册,启用后只能用管理员添加用户。
128129
- `SHOW_REGISTRATION_BUTTON`: 是否显示注册按钮。
129130
- `REQUIRE_SIGNIN_VIEW`: 是否所有页面都必须登录后才可访问。

integrations/mssql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ FROM = [email protected]
5555

5656
[service]
5757
REGISTER_EMAIL_CONFIRM = false
58+
REGISTER_MANUAL_CONFIRM = false
5859
ENABLE_NOTIFY_MAIL = false
5960
DISABLE_REGISTRATION = false
6061
ENABLE_CAPTCHA = false

integrations/mysql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ FROM = [email protected]
7676

7777
[service]
7878
REGISTER_EMAIL_CONFIRM = false
79+
REGISTER_MANUAL_CONFIRM = false
7980
ENABLE_NOTIFY_MAIL = false
8081
DISABLE_REGISTRATION = false
8182
ENABLE_CAPTCHA = false

integrations/mysql8.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ENABLED = false
5050

5151
[service]
5252
REGISTER_EMAIL_CONFIRM = false
53+
REGISTER_MANUAL_CONFIRM = false
5354
ENABLE_NOTIFY_MAIL = false
5455
DISABLE_REGISTRATION = false
5556
ENABLE_CAPTCHA = false

integrations/pgsql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ FROM = [email protected]
5656

5757
[service]
5858
REGISTER_EMAIL_CONFIRM = false
59+
REGISTER_MANUAL_CONFIRM = false
5960
ENABLE_NOTIFY_MAIL = false
6061
DISABLE_REGISTRATION = false
6162
ENABLE_CAPTCHA = false

integrations/sqlite.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ FROM = [email protected]
5252

5353
[service]
5454
REGISTER_EMAIL_CONFIRM = false
55+
REGISTER_MANUAL_CONFIRM = false
5556
ENABLE_NOTIFY_MAIL = true
5657
DISABLE_REGISTRATION = false
5758
ENABLE_CAPTCHA = false

modules/setting/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var Service struct {
1717
ActiveCodeLives int
1818
ResetPwdCodeLives int
1919
RegisterEmailConfirm bool
20+
RegisterManualConfirm bool
2021
EmailDomainWhitelist []string
2122
DisableRegistration bool
2223
AllowOnlyExternalRegistration bool
@@ -63,6 +64,11 @@ func newService() {
6364
Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
6465
Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
6566
Service.AllowOnlyExternalRegistration = sec.Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").MustBool()
67+
if !sec.Key("REGISTER_EMAIL_CONFIRM").MustBool() {
68+
Service.RegisterManualConfirm = sec.Key("REGISTER_EMAIL_CONFIRM").MustBool(false)
69+
} else {
70+
Service.RegisterManualConfirm = false
71+
}
6672
Service.EmailDomainWhitelist = sec.Key("EMAIL_DOMAIN_WHITELIST").Strings(",")
6773
Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!(Service.DisableRegistration || Service.AllowOnlyExternalRegistration))
6874
Service.ShowMilestonesDashboardPage = sec.Key("SHOW_MILESTONES_DASHBOARD_PAGE").MustBool(true)

routers/user/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
949949
Name: form.UserName,
950950
Email: form.Email,
951951
Passwd: form.Password,
952-
IsActive: !setting.Service.RegisterEmailConfirm,
952+
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
953953
LoginType: models.LoginOAuth2,
954954
LoginSource: loginSource.ID,
955955
LoginName: gothUser.(goth.User).UserID,
@@ -1144,7 +1144,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
11441144
Name: form.UserName,
11451145
Email: form.Email,
11461146
Passwd: form.Password,
1147-
IsActive: !setting.Service.RegisterEmailConfirm,
1147+
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
11481148
}
11491149
if err := models.CreateUser(u); err != nil {
11501150
switch {

0 commit comments

Comments
 (0)