delete token from redis

This commit is contained in:
Aravinth Manivannan 2021-06-10 18:34:36 +05:30
parent 43864cd991
commit 577b0326c9
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88

View file

@ -178,7 +178,7 @@ impl MCaptchaRedisConnection {
Ok(serde_json::from_str(&challege).unwrap())
}
/// Get PoW Challenge object from Redis
/// Delete PoW Challenge object from Redis
pub async fn delete_challenge(&self, msg: &VerifyCaptchaResult) -> CaptchaResult<()> {
let _: () = self
.0
@ -221,6 +221,15 @@ impl MCaptchaRedisConnection {
_ => Err(CaptchaError::MCaptchaRedisModuleError),
}
}
/// Delete PoW Token object from Redis
pub async fn delete_token(&self, msg: &VerifyCaptchaResult) -> CaptchaResult<()> {
//use redis::RedisResult;
// mcaptcha:token:captcha::token
let key = format!("mcaptcha:token:{}:{}", &msg.key, &msg.token);
self.0.exec(redis::cmd("DEL").arg(&[&key])).await?;
Ok(())
}
}
#[cfg(test)]
@ -316,6 +325,9 @@ pub mod tests {
challenge_msg.token = CHALLENGE.into();
assert!(r.get_token(&challenge_msg).await.unwrap());
r.add_token(&add_challenge_msg).await.unwrap();
assert!(r.delete_token(&challenge_msg).await.is_ok());
assert!(r.delete_captcha(CAPTCHA_NAME).await.is_ok());
}
}