Check for duplicate email

This commit is contained in:
2023-05-25 09:42:43 +02:00
parent bce6a85536
commit 4ba4d10fce
2 changed files with 25 additions and 2 deletions

View File

@ -20,3 +20,15 @@ pub async fn create_account(name: &str, email: &str) -> anyhow::Result<User> {
Ok(res)
})
}
/// Check if an email address is already associated with an account
pub async fn exists_email(email: &str) -> anyhow::Result<bool> {
db_connection::execute(|conn| {
let count: i64 = users::table
.filter(users::email.eq(email))
.count()
.get_result(conn)?;
Ok(count != 0)
})
}