feat: implement get_secret_from_captcha for db-sqlx-mariadb

This commit is contained in:
realaravinth
2022-07-23 15:49:41 +05:30
parent 6f5c09185f
commit a50763f520
2 changed files with 41 additions and 0 deletions

View File

@@ -287,6 +287,22 @@ impl MCDatabase for Database {
Ok(secret)
}
/// get a user's secret from a captcha key
async fn get_secret_from_captcha(&self, key: &str) -> DBResult<Secret> {
let secret = sqlx::query_as!(
Secret,
r#"SELECT secret FROM mcaptcha_users WHERE ID = (
SELECT user_id FROM mcaptcha_config WHERE captcha_key = ?
)"#,
key,
)
.fetch_one(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, DBError::AccountNotFound))?;
Ok(secret)
}
/// update a user's secret
async fn update_secret(&self, username: &str, secret: &str) -> DBResult<()> {
sqlx::query!(