Extract EmailSingup::ensure_email_not_blocked()
This commit is contained in:
parent
3b3148fa6b
commit
832479a706
@ -61,9 +61,7 @@ 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));
|
||||
}
|
||||
Self::ensure_email_not_blocked(conn, email)?;
|
||||
|
||||
conn.transaction(|| {
|
||||
Self::ensure_user_not_exist_by_email(conn, email)?;
|
||||
@ -95,9 +93,8 @@ 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));
|
||||
}
|
||||
Self::ensure_email_not_blocked(conn, &self.email)?;
|
||||
|
||||
conn.transaction(|| {
|
||||
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
|
||||
if self.expired() {
|
||||
@ -109,9 +106,8 @@ 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));
|
||||
}
|
||||
Self::ensure_email_not_blocked(conn, &self.email)?;
|
||||
|
||||
conn.transaction(|| {
|
||||
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
|
||||
let user = NewUser::new_local(
|
||||
@ -133,6 +129,14 @@ impl EmailSignup {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_email_not_blocked(conn: &DbConn, email: &str) -> Result<()> {
|
||||
if let Some(x) = BlocklistedEmail::matches_blocklist(conn, email)? {
|
||||
Err(Error::Blocklisted(x.notify_user, x.notification_text))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_user_not_exist_by_email(conn: &DbConn, email: &str) -> Result<()> {
|
||||
if User::email_used(conn, email)? {
|
||||
let _rows = Self::delete_existings_by_email(conn, email)?;
|
||||
|
Loading…
Reference in New Issue
Block a user