mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-14 13:08:27 +03:00
feat: def get_email trait
This commit is contained in:
parent
aad49dbb94
commit
6e45c643b1
3 changed files with 18 additions and 0 deletions
|
@ -41,6 +41,7 @@ pub enum DBError {
|
|||
/// Account not found
|
||||
#[error("Account not found")]
|
||||
AccountNotFound,
|
||||
|
||||
/// Captcha not found
|
||||
#[error("Captcha not found")]
|
||||
CaptchaNotFound,
|
||||
|
|
|
@ -113,6 +113,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||
/// check if username exists
|
||||
async fn username_exists(&self, username: &str) -> DBResult<bool>;
|
||||
|
||||
/// get user email
|
||||
async fn get_email(&self, username: &str) -> DBResult<Option<String>>;
|
||||
|
||||
/// check if email exists
|
||||
async fn email_exists(&self, email: &str) -> DBResult<bool>;
|
||||
|
||||
|
|
|
@ -65,6 +65,17 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||
assert_eq!(name_hash.hash, p.hash, "user password matches");
|
||||
assert_eq!(name_hash.username, p.username, "username matches");
|
||||
|
||||
// testing get_email
|
||||
assert_eq!(
|
||||
db.get_email(p.username)
|
||||
.await
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
p.email.unwrap()
|
||||
);
|
||||
|
||||
// testing email exists
|
||||
assert!(
|
||||
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
|
||||
|
@ -119,6 +130,9 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||
"user registration with email is deleted; so email shouldn't exsit"
|
||||
);
|
||||
|
||||
// testing get_email = None
|
||||
assert_eq!(db.get_email(p.username).await.unwrap(), None);
|
||||
|
||||
// testing update email
|
||||
let update_email = UpdateEmail {
|
||||
username: p.username,
|
||||
|
|
Loading…
Add table
Reference in a new issue