-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmethod.rs
More file actions
65 lines (54 loc) · 1.57 KB
/
Copy pathmethod.rs
File metadata and controls
65 lines (54 loc) · 1.57 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::sync::Arc;
use async_trait::async_trait;
use shield::{Method, MethodAction, ShieldError, User, erased_method};
use crate::{
actions::{EmailSignInAction, EmailSignInCallbackAction},
options::EmailOptions,
provider::EmailProvider,
storage::EmailStorage,
};
pub const EMAIL_METHOD_ID: &str = "email";
pub struct EmailMethod<U: User> {
options: EmailOptions,
storage: Arc<dyn EmailStorage<U>>,
}
impl<U: User> EmailMethod<U> {
pub fn new<S: EmailStorage<U> + 'static>(options: EmailOptions, storage: S) -> Self {
Self {
options,
storage: Arc::new(storage),
}
}
}
#[async_trait]
impl<U: User + 'static> Method for EmailMethod<U> {
type Provider = EmailProvider;
type Connection = ();
type Session = ();
fn id(&self) -> String {
EMAIL_METHOD_ID.to_owned()
}
fn actions(&self) -> Vec<Box<dyn MethodAction<Self::Provider, Self::Session>>> {
vec![
Box::new(EmailSignInAction::new(
self.options.clone(),
self.storage.clone(),
)),
Box::new(EmailSignInCallbackAction::new(
self.options.clone(),
self.storage.clone(),
)),
]
}
async fn providers(&self) -> Result<Vec<Self::Provider>, ShieldError> {
Ok(vec![EmailProvider])
}
async fn user_connections(
&self,
_user_id: &str,
_provider_id: Option<&str>,
) -> Result<Vec<Self::Connection>, ShieldError> {
Ok(vec![])
}
}
erased_method!(EmailMethod, <U: User>);