GetCurrentVisitor count
This commit is contained in:
parent
24e75f7cc9
commit
a4929922bf
2 changed files with 26 additions and 2 deletions
|
@ -67,8 +67,6 @@ async fn main() -> std::io::Result<()> {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
p
|
|
||||||
|
|
||||||
// create and start MCaptcha actor that uses the above defense configuration
|
// create and start MCaptcha actor that uses the above defense configuration
|
||||||
// This is what manages the difficulty factor of sites that an mCaptcha protects
|
// This is what manages the difficulty factor of sites that an mCaptcha protects
|
||||||
let mcaptcha = MCaptchaBuilder::default()
|
let mcaptcha = MCaptchaBuilder::default()
|
||||||
|
|
|
@ -229,6 +229,19 @@ impl Handler<AddVisitor> for MCaptcha {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Message to get the visitor count
|
||||||
|
#[derive(Message)]
|
||||||
|
#[rtype(result = "u32")]
|
||||||
|
pub struct GetCurrentVisitorCount;
|
||||||
|
|
||||||
|
impl Handler<GetCurrentVisitorCount> for MCaptcha {
|
||||||
|
type Result = MessageResult<GetCurrentVisitorCount>;
|
||||||
|
|
||||||
|
fn handle(&mut self, _: GetCurrentVisitorCount, _ctx: &mut Self::Context) -> Self::Result {
|
||||||
|
MessageResult(self.visitor_threshold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -331,4 +344,17 @@ pub mod tests {
|
||||||
Some(CaptchaError::PleaseSetValue("duration".into()))
|
Some(CaptchaError::PleaseSetValue("duration".into()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn get_current_visitor_count_works() {
|
||||||
|
let addr: MyActor = get_counter().start();
|
||||||
|
|
||||||
|
addr.send(AddVisitor).await.unwrap();
|
||||||
|
addr.send(AddVisitor).await.unwrap();
|
||||||
|
addr.send(AddVisitor).await.unwrap();
|
||||||
|
addr.send(AddVisitor).await.unwrap();
|
||||||
|
let count = addr.send(GetCurrentVisitorCount).await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(count, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue