Skip to content

Commit e484496

Browse files
committed
Add a configuration option to make email optional for password registration
1 parent 7d82da0 commit e484496

File tree

18 files changed

+482
-97
lines changed

18 files changed

+482
-97
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+
password_registration_email_required: account_config.password_registration_email_required,
214215
registration_token_required: account_config.registration_token_required,
215216
email_change_allowed: account_config.email_change_allowed,
216217
displayname_change_allowed: account_config.displayname_change_allowed,

crates/config/src/sections/account.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ pub struct AccountConfig {
5050
#[serde(default = "default_false", skip_serializing_if = "is_default_false")]
5151
pub password_registration_enabled: bool,
5252

53+
/// Whether self-service password registrations require a valid email.
54+
/// Defaults to `true`.
55+
///
56+
/// This has no effect if password registration is disabled.
57+
#[serde(default = "default_true", skip_serializing_if = "is_default_true")]
58+
pub password_registration_email_required: bool,
59+
5360
/// Whether users are allowed to change their passwords. Defaults to `true`.
5461
///
5562
/// This has no effect if password login is disabled.
@@ -89,6 +96,7 @@ impl Default for AccountConfig {
8996
email_change_allowed: default_true(),
9097
displayname_change_allowed: default_true(),
9198
password_registration_enabled: default_false(),
99+
password_registration_email_required: default_true(),
92100
password_change_allowed: default_true(),
93101
password_recovery_enabled: default_false(),
94102
account_deactivation_allowed: default_true(),

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 a valid email address is required for password registrations.
68+
pub password_registration_email_required: bool,
69+
6770
/// Whether registration tokens are required for password registrations.
6871
pub registration_token_required: bool,
6972

crates/handlers/src/admin/v1/site_config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub struct SiteConfig {
2222
/// Whether password registration is enabled.
2323
pub password_registration_enabled: bool,
2424

25+
/// Whether a valid email address is required for password registrations.
26+
pub password_registration_email_required: bool,
27+
2528
/// Whether registration tokens are required for password registrations.
2629
pub registration_token_required: bool,
2730

@@ -59,6 +62,7 @@ pub fn doc(operation: TransformOperation) -> TransformOperation {
5962
server_name: "example.com".to_owned(),
6063
password_login_enabled: true,
6164
password_registration_enabled: true,
65+
password_registration_email_required: true,
6266
registration_token_required: true,
6367
email_change_allowed: true,
6468
displayname_change_allowed: true,
@@ -80,6 +84,7 @@ pub async fn handler(
8084
server_name: site_config.server_name,
8185
password_login_enabled: site_config.password_login_enabled,
8286
password_registration_enabled: site_config.password_registration_enabled,
87+
password_registration_email_required: site_config.password_registration_email_required,
8388
registration_token_required: site_config.registration_token_required,
8489
email_change_allowed: site_config.email_change_allowed,
8590
displayname_change_allowed: site_config.displayname_change_allowed,

crates/handlers/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub fn test_site_config() -> SiteConfig {
140140
email_change_allowed: true,
141141
displayname_change_allowed: true,
142142
password_change_allowed: true,
143+
password_registration_email_required: true,
143144
account_recovery_allowed: true,
144145
account_deactivation_allowed: true,
145146
captcha: None,

0 commit comments

Comments
 (0)