Check email block list when email sign-up

This commit is contained in:
Kitaiti Makoto
2023-01-03 14:34:55 +09:00
parent 8c098def61
commit b38d55f486
6 changed files with 99 additions and 31 deletions
+3 -5
View File
@@ -126,11 +126,9 @@ pub(crate) mod tests {
.id,
various[1].id
);
assert!(
BlocklistedEmail::matches_blocklist(&conn, no_match)
.unwrap()
.is_none()
);
assert!(BlocklistedEmail::matches_blocklist(&conn, no_match)
.unwrap()
.is_none());
Ok(())
});
}
+11
View File
@@ -1,4 +1,5 @@
use crate::{
blocklisted_emails::BlocklistedEmail,
db_conn::DbConn,
schema::email_signups,
users::{NewUser, Role, User},
@@ -60,6 +61,10 @@ pub struct NewEmailSignup<'a> {
impl EmailSignup {
pub fn start(conn: &DbConn, email: &str) -> Result<Token> {
if let Some(x) = BlocklistedEmail::matches_blocklist(conn, email)? {
return Err(Error::Blocklisted(x.notify_user, x.notification_text));
}
conn.transaction(|| {
Self::ensure_user_not_exist_by_email(conn, email)?;
let _rows = Self::delete_existings_by_email(conn, email)?;
@@ -90,6 +95,9 @@ impl EmailSignup {
}
pub fn confirm(&self, conn: &DbConn) -> Result<()> {
if let Some(x) = BlocklistedEmail::matches_blocklist(conn, &self.email)? {
return Err(Error::Blocklisted(x.notify_user, x.notification_text));
}
conn.transaction(|| {
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
if self.expired() {
@@ -101,6 +109,9 @@ impl EmailSignup {
}
pub fn complete(&self, conn: &DbConn, username: String, password: String) -> Result<User> {
if let Some(x) = BlocklistedEmail::matches_blocklist(conn, &self.email)? {
return Err(Error::Blocklisted(x.notify_user, x.notification_text));
}
conn.transaction(|| {
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
let user = NewUser::new_local(
+1 -6
View File
@@ -107,12 +107,7 @@ impl Follow {
res.notify(conn)?;
let accept = res.build_accept(from, target, follow)?;
broadcast(
target,
accept,
vec![from.clone()],
CONFIG.proxy().cloned(),
);
broadcast(target, accept, vec![from.clone()], CONFIG.proxy().cloned());
Ok(res)
}
+2 -1
View File
@@ -133,7 +133,8 @@ impl Post {
.filter(posts::id.eq_any(ids))
.filter(posts::published.eq(true))
.count()
.load(conn)?.first()
.load(conn)?
.first()
.cloned()
.ok_or(Error::NotFound)
}
+3 -13
View File
@@ -291,13 +291,7 @@ mod tests {
"all".to_owned(),
)
.unwrap();
List::new(
conn,
"languages I speak",
Some(&users[1]),
ListType::Prefix,
)
.unwrap();
List::new(conn, "languages I speak", Some(&users[1]), ListType::Prefix).unwrap();
let tl2_u1 = Timeline::new_for_user(
conn,
users[0].id,
@@ -337,18 +331,14 @@ mod tests {
let tl_instance = Timeline::list_for_user(conn, None).unwrap();
assert_eq!(3, tl_instance.len()); // there are also the local and federated feed by default
assert!(tl_instance
.iter()
.any(|tl| *tl == tl1_instance));
assert!(tl_instance.iter().any(|tl| *tl == tl1_instance));
tl1_u1.name = "My Super TL".to_owned();
let new_tl1_u2 = tl1_u2.update(conn).unwrap();
let tl_u2 = Timeline::list_for_user(conn, Some(users[1].id)).unwrap();
assert_eq!(2, tl_u2.len()); // same here
assert!(tl_u2
.iter()
.any(|tl| *tl == new_tl1_u2));
assert!(tl_u2.iter().any(|tl| *tl == new_tl1_u2));
Ok(())
});