Skip to content

Commit e0dbdbe

Browse files
committed
feat: [#654] remove config option email_verification_enabled
The config option: ```toml [mail] email_verification_enabled = false ``` was replaced with: ```toml [registration] [registration.email] verified = true ```
1 parent 29cc9dc commit e0dbdbe

File tree

8 files changed

+53
-46
lines changed

8 files changed

+53
-46
lines changed

src/config/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ mod tests {
433433
connect_url = "sqlite://data.db?mode=rwc"
434434
435435
[mail]
436-
email_verification_enabled = false
437436
from = "example@email.com"
438437
reply_to = "noreply@email.com"
439438

src/config/v2/mail.rs

-9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ use serde::{Deserialize, Serialize};
44
/// SMTP configuration.
55
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
66
pub struct Mail {
7-
/// Whether or not to enable email verification on signup.
8-
#[serde(default = "Mail::default_email_verification_enabled")]
9-
pub email_verification_enabled: bool,
10-
117
/// The email address to send emails from.
128
#[serde(default = "Mail::default_from")]
139
pub from: Mailbox,
@@ -24,7 +20,6 @@ pub struct Mail {
2420
impl Default for Mail {
2521
fn default() -> Self {
2622
Self {
27-
email_verification_enabled: Self::default_email_verification_enabled(),
2823
from: Self::default_from(),
2924
reply_to: Self::default_reply_to(),
3025
smtp: Self::default_smtp(),
@@ -33,10 +28,6 @@ impl Default for Mail {
3328
}
3429

3530
impl Mail {
36-
fn default_email_verification_enabled() -> bool {
37-
false
38-
}
39-
4031
fn default_from() -> Mailbox {
4132
"example@email.com".parse().expect("valid mailbox")
4233
}

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
//! connect_url = "sqlite://data.db?mode=rwc"
192192
//!
193193
//! [mail]
194-
//! email_verification_enabled = false
195194
//! from = "example@email.com"
196195
//! reply_to = "noreply@email.com"
197196
//!

src/services/authentication.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ impl Service {
7070
let settings = self.configuration.settings.read().await;
7171

7272
// Fail login if email verification is required and this email is not verified
73-
if settings.mail.email_verification_enabled && !user_profile.email_verified {
74-
return Err(ServiceError::EmailNotVerified);
73+
if let Some(registration) = &settings.registration {
74+
if let Some(email) = &registration.email {
75+
if email.verified && !user_profile.email_verified {
76+
return Err(ServiceError::EmailNotVerified);
77+
}
78+
}
7579
}
7680

7781
// Drop read lock on settings

src/services/user.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,24 @@ impl RegistrationService {
125125
drop(self.user_repository.grant_admin_role(&user_id).await);
126126
}
127127

128-
if settings.mail.email_verification_enabled {
129-
if let Some(email) = opt_email {
130-
let mail_res = self
131-
.mailer
132-
.send_verification_mail(&email, &registration_form.username, user_id, api_base_url)
133-
.await;
134-
135-
if mail_res.is_err() {
136-
drop(self.user_repository.delete(&user_id).await);
137-
return Err(ServiceError::FailedToSendVerificationEmail);
128+
match &registration.email {
129+
Some(email) => {
130+
if email.verified {
131+
// Email verification is enabled
132+
if let Some(email) = opt_email {
133+
let mail_res = self
134+
.mailer
135+
.send_verification_mail(&email, &registration_form.username, user_id, api_base_url)
136+
.await;
137+
138+
if mail_res.is_err() {
139+
drop(self.user_repository.delete(&user_id).await);
140+
return Err(ServiceError::FailedToSendVerificationEmail);
141+
}
142+
}
138143
}
139144
}
145+
None => (),
140146
}
141147

142148
Ok(user_id)

src/web/api/client/v1/contexts/settings/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub struct Database {
6666

6767
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
6868
pub struct Mail {
69-
pub email_verification_enabled: bool,
7069
pub from: String,
7170
pub reply_to: String,
7271
pub smtp: Smtp,
@@ -179,7 +178,6 @@ impl From<DomainDatabase> for Database {
179178
impl From<DomainMail> for Mail {
180179
fn from(mail: DomainMail) -> Self {
181180
Self {
182-
email_verification_enabled: mail.email_verification_enabled,
183181
from: mail.from.to_string(),
184182
reply_to: mail.reply_to.to_string(),
185183
smtp: Smtp::from(mail.smtp),

src/web/api/server/v1/contexts/settings/mod.rs

+31-19
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,55 @@
3030
//! ```json
3131
//! {
3232
//! "data": {
33+
//! "version": "2",
34+
//! "logging": {
35+
//! "threshold": "info"
36+
//! },
3337
//! "website": {
3438
//! "name": "Torrust"
3539
//! },
3640
//! "tracker": {
37-
//! "url": "udp://localhost:6969",
38-
//! "mode": "public",
3941
//! "api_url": "http://localhost:1212/",
40-
//! "token": "MyAccessToken",
41-
//! "token_valid_seconds": 7257600
42+
//! "listed": false,
43+
//! "private": false,
44+
//! "token": "***",
45+
//! "token_valid_seconds": 7257600,
46+
//! "url": "udp://localhost:6969"
4247
//! },
4348
//! "net": {
44-
//! "port": 3001,
45-
//! "base_url": null
49+
//! "base_url": null,
50+
//! "bind_address": "0.0.0.0:3001",
51+
//! "tsl": null
4652
//! },
4753
//! "auth": {
48-
//! "min_password_length": 6,
49-
//! "max_password_length": 64,
50-
//! "secret_key": "MaxVerstappenWC2021"
54+
//! "secret_key": "***",
55+
//! "password_constraints": {
56+
//! "max_password_length": 64,
57+
//! "min_password_length": 6
58+
//! }
5159
//! },
5260
//! "database": {
53-
//! "connect_url": "sqlite://./storage/database/data.db?mode=rwc"
61+
//! "connect_url": "sqlite://data.db?mode=rwc"
5462
//! },
5563
//! "mail": {
5664
//! "email_verification_enabled": false,
5765
//! "from": "example@email.com",
5866
//! "reply_to": "noreply@email.com",
59-
//! "username": "",
60-
//! "password": "",
61-
//! "server": "",
62-
//! "port": 25
67+
//! "smtp": {
68+
//! "port": 25,
69+
//! "server": "",
70+
//! "credentials": {
71+
//! "password": "***",
72+
//! "username": ""
73+
//! }
74+
//! }
6375
//! },
6476
//! "image_cache": {
65-
//! "max_request_timeout_ms": 1000,
6677
//! "capacity": 128000000,
6778
//! "entry_size_limit": 4000000,
68-
//! "user_quota_period_seconds": 3600,
69-
//! "user_quota_bytes": 64000000
79+
//! "max_request_timeout_ms": 1000,
80+
//! "user_quota_bytes": 64000000,
81+
//! "user_quota_period_seconds": 3600
7082
//! },
7183
//! "api": {
7284
//! "default_torrent_page_size": 10,
@@ -79,8 +91,8 @@
7991
//! }
8092
//! },
8193
//! "tracker_statistics_importer": {
94+
//! "port": 3002,
8295
//! "torrent_info_update_interval": 3600
83-
//! "port": 3002
8496
//! }
8597
//! }
8698
//! }
@@ -107,7 +119,7 @@
107119
//! --header "Content-Type: application/json" \
108120
//! --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
109121
//! --request POST \
110-
//! --data '{"website":{"name":"Torrust"},"tracker":{"url":"udp://localhost:6969","mode":"public","api_url":"http://localhost:1212/","token":"MyAccessToken","token_valid_seconds":7257600},"net":{"port":3001,"base_url":null},"auth":{"min_password_length":6,"max_password_length":64,"secret_key":"MaxVerstappenWC2021"},"database":{"connect_url":"sqlite://./storage/database/data.db?mode=rwc"},"mail":{"email_verification_enabled":false,"from":"example@email.com","reply_to":"noreply@email.com","username":"","password":"","server":"","port":25},"image_cache":{"max_request_timeout_ms":1000,"capacity":128000000,"entry_size_limit":4000000,"user_quota_period_seconds":3600,"user_quota_bytes":64000000},"api":{"default_torrent_page_size":10,"max_torrent_page_size":30},"tracker_statistics_importer":{"torrent_info_update_interval":3600}}' \
122+
//! --data '{"website":{"name":"Torrust"},"tracker":{"url":"udp://localhost:6969","mode":"public","api_url":"http://localhost:1212/","token":"MyAccessToken","token_valid_seconds":7257600},"net":{"port":3001,"base_url":null},"auth":{"min_password_length":6,"max_password_length":64,"secret_key":"MaxVerstappenWC2021"},"database":{"connect_url":"sqlite://./storage/database/data.db?mode=rwc"},"mail":{"from":"example@email.com","reply_to":"noreply@email.com","username":"","password":"","server":"","port":25},"image_cache":{"max_request_timeout_ms":1000,"capacity":128000000,"entry_size_limit":4000000,"user_quota_period_seconds":3600,"user_quota_bytes":64000000},"api":{"default_torrent_page_size":10,"max_torrent_page_size":30},"tracker_statistics_importer":{"torrent_info_update_interval":3600}}' \
111123
//! "http://127.0.0.1:3001/v1/settings"
112124
//! ```
113125
//!

tests/common/contexts/settings/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pub struct Database {
7272

7373
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
7474
pub struct Mail {
75-
pub email_verification_enabled: bool,
7675
pub from: String,
7776
pub reply_to: String,
7877
pub smtp: Smtp,
@@ -206,7 +205,6 @@ impl From<DomainDatabase> for Database {
206205
impl From<DomainMail> for Mail {
207206
fn from(mail: DomainMail) -> Self {
208207
Self {
209-
email_verification_enabled: mail.email_verification_enabled,
210208
from: mail.from.to_string(),
211209
reply_to: mail.reply_to.to_string(),
212210
smtp: mail.smtp.into(),

0 commit comments

Comments
 (0)