redis: rename mcaptcha
This commit is contained in:
parent
510606895a
commit
c02377d834
1 changed files with 18 additions and 2 deletions
|
@ -40,6 +40,7 @@ const ADD_VISITOR: &str = "MCAPTCHA_CACHE.ADD_VISITOR";
|
||||||
const DEL: &str = "MCAPTCHA_CACHE.DELETE_CAPTCHA";
|
const DEL: &str = "MCAPTCHA_CACHE.DELETE_CAPTCHA";
|
||||||
const ADD_CAPTCHA: &str = "MCAPTCHA_CACHE.ADD_CAPTCHA";
|
const ADD_CAPTCHA: &str = "MCAPTCHA_CACHE.ADD_CAPTCHA";
|
||||||
const CAPTCHA_EXISTS: &str = "MCAPTCHA_CACHE.CAPTCHA_EXISTS";
|
const CAPTCHA_EXISTS: &str = "MCAPTCHA_CACHE.CAPTCHA_EXISTS";
|
||||||
|
const RENAME_CAPTCHA: &str = "MCAPTCHA_CACHE.RENAME_CAPTCHA";
|
||||||
const ADD_CHALLENGE: &str = "MCAPTCHA_CACHE.ADD_CHALLENGE";
|
const ADD_CHALLENGE: &str = "MCAPTCHA_CACHE.ADD_CHALLENGE";
|
||||||
const GET_CHALLENGE: &str = "MCAPTCHA_CACHE.GET_CHALLENGE";
|
const GET_CHALLENGE: &str = "MCAPTCHA_CACHE.GET_CHALLENGE";
|
||||||
const DELETE_CHALLENGE: &str = "MCAPTCHA_CACHE.DELETE_CHALLENGE";
|
const DELETE_CHALLENGE: &str = "MCAPTCHA_CACHE.DELETE_CHALLENGE";
|
||||||
|
@ -90,6 +91,7 @@ impl MCaptchaRedisConnection {
|
||||||
ADD_CHALLENGE,
|
ADD_CHALLENGE,
|
||||||
GET_CHALLENGE,
|
GET_CHALLENGE,
|
||||||
DELETE_CHALLENGE,
|
DELETE_CHALLENGE,
|
||||||
|
RENAME_CAPTCHA,
|
||||||
];
|
];
|
||||||
|
|
||||||
for cmd in commands.iter() {
|
for cmd in commands.iter() {
|
||||||
|
@ -159,6 +161,14 @@ impl MCaptchaRedisConnection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rename mCaptcha object in Redis
|
||||||
|
pub async fn rename_captcha(&self, name: &str, rename_to: &str) -> CaptchaResult<()> {
|
||||||
|
self.0
|
||||||
|
.exec(redis::cmd(RENAME_CAPTCHA).arg(&[name, rename_to]))
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Add PoW Challenge object to Redis
|
/// Add PoW Challenge object to Redis
|
||||||
pub async fn add_challenge(
|
pub async fn add_challenge(
|
||||||
&self,
|
&self,
|
||||||
|
@ -219,7 +229,6 @@ impl MCaptchaRedisConnection {
|
||||||
// mcaptcha:token:captcha::token
|
// mcaptcha:token:captcha::token
|
||||||
let key = format!("mcaptcha:token:{}:{}", &msg.key, &msg.token);
|
let key = format!("mcaptcha:token:{}:{}", &msg.key, &msg.token);
|
||||||
let res = self.0.exec(redis::cmd("DEL").arg(&[&key])).await?;
|
let res = self.0.exec(redis::cmd("DEL").arg(&[&key])).await?;
|
||||||
println!("{}", res);
|
|
||||||
match res {
|
match res {
|
||||||
1 => Ok(true),
|
1 => Ok(true),
|
||||||
0 => Ok(false),
|
0 => Ok(false),
|
||||||
|
@ -244,6 +253,7 @@ pub mod tests {
|
||||||
use crate::redis::*;
|
use crate::redis::*;
|
||||||
|
|
||||||
const CAPTCHA_NAME: &str = "REDIS_CAPTCHA_TEST";
|
const CAPTCHA_NAME: &str = "REDIS_CAPTCHA_TEST";
|
||||||
|
const RENAME_CAPTCHA_NAME: &str = "RENAME_REDIS_CAPTCHA_TEST";
|
||||||
const REDIS_URL: &str = "redis://127.0.1.1/";
|
const REDIS_URL: &str = "redis://127.0.1.1/";
|
||||||
const CHALLENGE: &str = "randomchallengestring";
|
const CHALLENGE: &str = "randomchallengestring";
|
||||||
|
|
||||||
|
@ -335,6 +345,12 @@ pub mod tests {
|
||||||
|
|
||||||
assert!(r.ping().await);
|
assert!(r.ping().await);
|
||||||
|
|
||||||
assert!(r.delete_captcha(CAPTCHA_NAME).await.is_ok());
|
assert!(r
|
||||||
|
.rename_captcha(CAPTCHA_NAME, RENAME_CAPTCHA_NAME)
|
||||||
|
.await
|
||||||
|
.is_ok());
|
||||||
|
assert!(r.check_captcha_exists(RENAME_CAPTCHA_NAME).await.unwrap());
|
||||||
|
assert!(!r.check_captcha_exists(CAPTCHA_NAME).await.unwrap());
|
||||||
|
assert!(r.delete_captcha(RENAME_CAPTCHA_NAME).await.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue