mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-11-24 06:25:46 +00:00
feat: def get_email trait
This commit is contained in:
parent
aad49dbb94
commit
6e45c643b1
@ -41,6 +41,7 @@ pub enum DBError {
|
|||||||
/// Account not found
|
/// Account not found
|
||||||
#[error("Account not found")]
|
#[error("Account not found")]
|
||||||
AccountNotFound,
|
AccountNotFound,
|
||||||
|
|
||||||
/// Captcha not found
|
/// Captcha not found
|
||||||
#[error("Captcha not found")]
|
#[error("Captcha not found")]
|
||||||
CaptchaNotFound,
|
CaptchaNotFound,
|
||||||
|
|||||||
@ -113,6 +113,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
/// check if username exists
|
/// check if username exists
|
||||||
async fn username_exists(&self, username: &str) -> DBResult<bool>;
|
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
|
/// check if email exists
|
||||||
async fn email_exists(&self, email: &str) -> DBResult<bool>;
|
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.hash, p.hash, "user password matches");
|
||||||
assert_eq!(name_hash.username, p.username, "username 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
|
// testing email exists
|
||||||
assert!(
|
assert!(
|
||||||
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
|
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"
|
"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
|
// testing update email
|
||||||
let update_email = UpdateEmail {
|
let update_email = UpdateEmail {
|
||||||
username: p.username,
|
username: p.username,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user