newtypes::LocalUserId,
schema::local_user::dsl::{
accepted_application,
+ email,
email_verified,
local_user,
password_encrypted,
impl LocalUser {
pub async fn update_password(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id: LocalUserId,
new_password: &str,
) -> Result<Self, Error> {
.await
}
- pub async fn set_all_users_email_verified(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn set_all_users_email_verified(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_user)
.set(email_verified.eq(true))
}
pub async fn set_all_users_registration_applications_accepted(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_user)
.get_results::<Self>(conn)
.await
}
+
+ pub async fn is_email_taken(pool: &mut DbPool<'_>, email_: &str) -> Result<bool, Error> {
+ use diesel::dsl::{exists, select};
+ let conn = &mut get_conn(pool).await?;
+ select(exists(local_user.filter(email.eq(email_))))
+ .get_result(conn)
+ .await
+ }
}
#[async_trait]
type InsertForm = LocalUserInsertForm;
type UpdateForm = LocalUserUpdateForm;
type IdType = LocalUserId;
- async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_user.find(local_user_id).first::<Self>(conn).await
}
- async fn delete(pool: &DbPool, local_user_id: LocalUserId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(local_user.find(local_user_id))
.execute(conn)
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let mut form_with_encrypted_password = form.clone();
let password_hash =
let local_user_ = insert_into(local_user)
.values(form_with_encrypted_password)
.get_result::<Self>(conn)
- .await
- .expect("couldnt create local user");
+ .await?;
- let site_languages = SiteLanguage::read_local(pool).await;
+ let site_languages = SiteLanguage::read_local_raw(pool).await;
if let Ok(langs) = site_languages {
// if site exists, init user with site languages
LocalUserLanguage::update(pool, langs, local_user_.id).await?;
Ok(local_user_)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id: LocalUserId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {