1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use primitives::authorizer::Authorizer;
use primitives::grant::Grant;
use super::super::actix::{Handler, Message};
use super::super::AsActor;
pub struct Authorize {
pub grant: Grant,
}
impl Message for Authorize {
type Result = Result<String, ()>;
}
pub struct Extract {
pub token: String,
}
impl Message for Extract {
type Result = Result<Option<Grant>, ()>;
}
impl<A: Authorizer + 'static> Handler<Authorize> for AsActor<A> {
type Result = Result<String, ()>;
fn handle(&mut self, msg: Authorize, _: &mut Self::Context) -> Self::Result {
self.0.authorize(msg.grant)
}
}
impl<A: Authorizer + 'static> Handler<Extract> for AsActor<A> {
type Result = Result<Option<Grant>, ()>;
fn handle(&mut self, msg: Extract, _: &mut Self::Context) -> Self::Result {
self.0.extract(&msg.token)
}
}