feat: define interface for updating email of a user

This commit is contained in:
realaravinth 2022-05-11 15:25:23 +05:30
parent 8861201727
commit 58216f0f63
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 26 additions and 0 deletions

View file

@ -71,6 +71,15 @@ pub struct Register<'a> {
pub email: Option<&'a str>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
/// data required to update them email of a user
pub struct UpdateEmail<'a> {
/// username of the user
pub username: &'a str,
/// new email address of the user
pub new_email: &'a str,
}
#[async_trait]
/// mCaptcha's database requirements. To implement support for $Database, kindly implement this
/// trait.
@ -89,6 +98,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
/// check if email exists
async fn email_exists(&self, email: &str) -> DBResult<bool>;
/// update a user's email
async fn update_email(&self, p: &UpdateEmail) -> DBResult<()>;
}
/// Trait to clone MCDatabase

View file

@ -55,4 +55,18 @@ pub async fn database_works<'a, T: MCDatabase>(db: &T, p: &Register<'a>) {
"user registration with email is deleted; so email shouldn't exsit"
);
let update_email = UpdateEmail {
username: p.username,
new_email: p.email.as_ref().unwrap(),
};
db.update_email(&update_email).await.unwrap();
println!(
"null user email: {}",
db.email_exists(p.email.as_ref().unwrap()).await.unwrap()
);
assert!(
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
"user was with empty email but email is set; so email should exsit"
);
}