Skip to content

Commit 685f476

Browse files
committed
Add config flag to require registration tokens for password registrations
1 parent ccb971d commit 685f476

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

crates/cli/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub fn site_config_from_config(
211211
password_login_enabled: password_config.enabled(),
212212
password_registration_enabled: password_config.enabled()
213213
&& account_config.password_registration_enabled,
214+
registration_token_required: account_config.registration_token_required,
214215
email_change_allowed: account_config.email_change_allowed,
215216
displayname_change_allowed: account_config.displayname_change_allowed,
216217
password_change_allowed: password_config.enabled()

crates/config/src/sections/account.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ pub struct AccountConfig {
7272
/// This has no effect if password login is disabled.
7373
#[serde(default = "default_false", skip_serializing_if = "is_default_false")]
7474
pub login_with_email_allowed: bool,
75+
76+
/// Whether registration tokens are required for password registrations.
77+
/// Defaults to `false`.
78+
///
79+
/// When enabled, users must provide a valid registration token during
80+
/// password registration. This has no effect if password registration
81+
/// is disabled.
82+
#[serde(default = "default_false", skip_serializing_if = "is_default_false")]
83+
pub registration_token_required: bool,
7584
}
7685

7786
impl Default for AccountConfig {
@@ -84,6 +93,7 @@ impl Default for AccountConfig {
8493
password_recovery_enabled: default_false(),
8594
account_deactivation_allowed: default_true(),
8695
login_with_email_allowed: default_false(),
96+
registration_token_required: default_false(),
8797
}
8898
}
8999
}
@@ -98,6 +108,7 @@ impl AccountConfig {
98108
&& is_default_false(&self.password_recovery_enabled)
99109
&& is_default_true(&self.account_deactivation_allowed)
100110
&& is_default_false(&self.login_with_email_allowed)
111+
&& is_default_false(&self.registration_token_required)
101112
}
102113
}
103114

crates/data-model/src/site_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub struct SiteConfig {
6464
/// Whether password registration is enabled.
6565
pub password_registration_enabled: bool,
6666

67+
/// Whether registration tokens are required for password registrations.
68+
pub registration_token_required: bool,
69+
6770
/// Whether users can change their email.
6871
pub email_change_allowed: bool,
6972

crates/handlers/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub fn test_site_config() -> SiteConfig {
136136
imprint: None,
137137
password_login_enabled: true,
138138
password_registration_enabled: true,
139+
registration_token_required: false,
139140
email_change_allowed: true,
140141
displayname_change_allowed: true,
141142
password_change_allowed: true,

docs/config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,10 @@
25332533
"login_with_email_allowed": {
25342534
"description": "Whether users can log in with their email address. Defaults to `false`.\n\nThis has no effect if password login is disabled.",
25352535
"type": "boolean"
2536+
},
2537+
"registration_token_required": {
2538+
"description": "Whether registration tokens are required for password registrations. Defaults to `false`.\n\nWhen enabled, users must provide a valid registration token during password registration. This has no effect if password registration is disabled.",
2539+
"type": "boolean"
25362540
}
25372541
}
25382542
},

docs/reference/configuration.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ account:
320320
# Defaults to `false`.
321321
# This has no effect if password login is disabled.
322322
login_with_email_allowed: false
323+
324+
# Whether registration tokens are required for password registrations.
325+
#
326+
# Defaults to `false`.
327+
#
328+
# When enabled, users must provide a valid registration token during password
329+
# registration. This has no effect if password registration is disabled.
330+
registration_token_required: false
323331
```
324332
325333
## `captcha`
@@ -712,7 +720,7 @@ upstream_oauth2:
712720
# Additional parameters to include in the authorization request
713721
#additional_authorization_parameters:
714722
# foo: "bar"
715-
723+
716724
# Whether the `login_hint` should be forwarded to the provider in the
717725
# authorization request.
718726
#forward_login_hint: false

0 commit comments

Comments
 (0)