mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-29 04:38:59 +03:00
feat: get password using either username or email
This commit is contained in:
parent
fdf4f0bef9
commit
7e2be86c12
2 changed files with 20 additions and 2 deletions
|
@ -80,6 +80,15 @@ pub struct UpdateEmail<'a> {
|
||||||
pub new_email: &'a str,
|
pub new_email: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
/// types of credentials used as identifiers during login
|
||||||
|
pub enum Login<'a> {
|
||||||
|
/// username as login
|
||||||
|
Username(&'a str),
|
||||||
|
/// email as login
|
||||||
|
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.
|
||||||
|
@ -103,7 +112,7 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||||
async fn update_email(&self, p: &UpdateEmail) -> DBResult<()>;
|
async fn update_email(&self, p: &UpdateEmail) -> DBResult<()>;
|
||||||
|
|
||||||
/// get a user's password
|
/// get a user's password
|
||||||
async fn get_password(&self, username: &str) -> DBResult<String>;
|
async fn get_password(&self, l: &Login) -> DBResult<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to clone MCDatabase
|
/// Trait to clone MCDatabase
|
||||||
|
|
|
@ -30,10 +30,19 @@ pub async fn database_works<'a, T: MCDatabase>(db: &T, p: &Register<'a>) {
|
||||||
db.register(p).await.unwrap();
|
db.register(p).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.get_password(p.username).await.unwrap(),
|
db.get_password(&Login::Username(p.username)).await.unwrap(),
|
||||||
p.hash,
|
p.hash,
|
||||||
"user password matches"
|
"user password matches"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
db.get_password(&Login::Email(p.email.as_ref().unwrap()))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
p.hash,
|
||||||
|
"user password matches"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
|
db.email_exists(p.email.as_ref().unwrap()).await.unwrap(),
|
||||||
"user is registered so email should exsit"
|
"user is registered so email should exsit"
|
||||||
|
|
Loading…
Add table
Reference in a new issue