mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-13 19:15:39 +00:00
feat: define interface for updating email of a user
This commit is contained in:
@@ -71,6 +71,15 @@ pub struct Register<'a> {
|
|||||||
pub email: Option<&'a str>,
|
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]
|
#[async_trait]
|
||||||
/// mCaptcha's database requirements. To implement support for $Database, kindly implement this
|
/// mCaptcha's database requirements. To implement support for $Database, kindly implement this
|
||||||
/// trait.
|
/// trait.
|
||||||
@@ -89,6 +98,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
|
|
||||||
/// check if email exists
|
/// check if email exists
|
||||||
async fn email_exists(&self, email: &str) -> DBResult<bool>;
|
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
|
/// Trait to clone MCDatabase
|
||||||
|
|||||||
@@ -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"
|
"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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user