3 schema::email_verification::dsl::*,
4 source::email_verification::*,
5 utils::{get_conn, DbPool},
7 use diesel::{dsl::*, insert_into, result::Error, ExpressionMethods, QueryDsl};
8 use diesel_async::RunQueryDsl;
10 impl EmailVerification {
11 pub async fn create(pool: &DbPool, form: &EmailVerificationForm) -> Result<Self, Error> {
12 let conn = &mut get_conn(pool).await?;
13 insert_into(email_verification)
15 .get_result::<Self>(conn)
19 pub async fn read_for_token(pool: &DbPool, token: &str) -> Result<Self, Error> {
20 let conn = &mut get_conn(pool).await?;
22 .filter(verification_token.eq(token))
23 .filter(published.gt(now - 7.days()))
27 pub async fn delete_old_tokens_for_local_user(
29 local_user_id_: LocalUserId,
30 ) -> Result<usize, Error> {
31 let conn = &mut get_conn(pool).await?;
32 diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_)))