mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Forbid removing emails if they're required to register
This commit is contained in:
@@ -27,13 +27,21 @@ pub struct Service {
|
||||
|
||||
pub enum EmailRequirement {
|
||||
/// Users may change their email, but cannot remove it entirely.
|
||||
Always,
|
||||
Required,
|
||||
/// Users may change or remove their email.
|
||||
Optional,
|
||||
/// SMTP is not configured.
|
||||
/// Users may not change their email at all.
|
||||
Unavailable,
|
||||
}
|
||||
|
||||
impl EmailRequirement {
|
||||
#[must_use]
|
||||
pub fn may_change(&self) -> bool { matches!(self, Self::Required | Self::Optional) }
|
||||
|
||||
#[must_use]
|
||||
pub fn may_remove(&self) -> bool { matches!(self, Self::Optional) }
|
||||
}
|
||||
|
||||
struct Data {
|
||||
localpart_email: Arc<Map>,
|
||||
email_localpart: Arc<Map>,
|
||||
@@ -77,7 +85,7 @@ impl Service {
|
||||
pub fn email_requirement(&self) -> EmailRequirement {
|
||||
if let Some(smtp) = &self.services.config.smtp {
|
||||
if smtp.require_email_for_registration || smtp.require_email_for_token_registration {
|
||||
EmailRequirement::Always
|
||||
EmailRequirement::Required
|
||||
} else {
|
||||
EmailRequirement::Optional
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user