mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Remove a user's existing email before adding a new one
This commit is contained in:
@@ -25,6 +25,15 @@ pub struct Service {
|
|||||||
ratelimiter: DefaultKeyedRateLimiter<Address>,
|
ratelimiter: DefaultKeyedRateLimiter<Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum EmailRequirement {
|
||||||
|
/// Users may change their email, but cannot remove it entirely.
|
||||||
|
Always,
|
||||||
|
/// Users may change or remove their email.
|
||||||
|
Optional,
|
||||||
|
/// SMTP is not configured.
|
||||||
|
Unavailable,
|
||||||
|
}
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
localpart_email: Arc<Map>,
|
localpart_email: Arc<Map>,
|
||||||
email_localpart: Arc<Map>,
|
email_localpart: Arc<Map>,
|
||||||
@@ -64,6 +73,19 @@ impl Service {
|
|||||||
Quota::per_minute(nonzero!(10_u32)).allow_burst(nonzero!(2_u32));
|
Quota::per_minute(nonzero!(10_u32)).allow_burst(nonzero!(2_u32));
|
||||||
const VALIDATION_URL_PATH: &str = "/_continuwuity/3pid/email/validate";
|
const VALIDATION_URL_PATH: &str = "/_continuwuity/3pid/email/validate";
|
||||||
|
|
||||||
|
/// Check if users are required to have an email address.
|
||||||
|
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
|
||||||
|
} else {
|
||||||
|
EmailRequirement::Optional
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EmailRequirement::Unavailable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Send a validation message to an email address.
|
/// Send a validation message to an email address.
|
||||||
///
|
///
|
||||||
/// Returns the validation session ID on success.
|
/// Returns the validation session ID on success.
|
||||||
@@ -234,6 +256,9 @@ impl Service {
|
|||||||
| None => {
|
| None => {
|
||||||
// The supplied email is not already in use.
|
// The supplied email is not already in use.
|
||||||
|
|
||||||
|
// Remove the user's existing email first.
|
||||||
|
let _ = self.disassociate_localpart_email(localpart).await;
|
||||||
|
|
||||||
let email: &str = email.as_ref();
|
let email: &str = email.as_ref();
|
||||||
self.db.localpart_email.insert(localpart, email);
|
self.db.localpart_email.insert(localpart, email);
|
||||||
self.db.email_localpart.insert(email, localpart);
|
self.db.email_localpart.insert(email, localpart);
|
||||||
|
|||||||
Reference in New Issue
Block a user