use sofie::prelude::*;
use super::Account;
use crate::{Password, PasswordHash};
pub(crate) async fn register(
read: &Read,
email: Email,
password: &Password,
) -> Result<Option<Account>> {
let taken = Account::query()
.where_(Account::EMAIL.eq(email.clone()))
.exists(read)
.await?;
let password_hash = PasswordHash::new(password).await?;
if taken {
return Ok(None);
}
Ok(Some(Account {
meta: Meta::new()?,
email,
password_hash,
verified_at: None,
locale: None,
}))
}
pub(crate) fn without_password(email: Email) -> Result<Account> {
Ok(Account {
meta: Meta::new()?,
email,
password_hash: PasswordHash::unmatchable()?,
verified_at: None,
locale: None,
})
}