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
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 41 additions and 0 deletions

View file

@ -431,6 +431,31 @@
},
"query": "SELECT config_id from mcaptcha_config WHERE captcha_key = ?"
},
"b9258c2494d95701d19703cf5cd05a222057a0ccad943192138b1a4a94bf823b": {
"describe": {
"columns": [
{
"name": "secret",
"ordinal": 0,
"type_info": {
"char_set": 224,
"flags": {
"bits": 4101
},
"max_size": 200,
"type": "VarString"
}
}
],
"nullable": [
false
],
"parameters": {
"Right": 1
}
},
"query": "SELECT secret FROM mcaptcha_users WHERE ID = (\n SELECT user_id FROM mcaptcha_config WHERE captcha_key = ?\n )"
},
"b95e5a60a202cb646d5e76df8c7395e4bf881a6dd14e28e6f2e8b93e0536b331": {
"describe": {
"columns": [],

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!(