You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Save user emails in database
This commit is contained in:
@ -33,5 +33,5 @@ pub use self::{
|
||||
},
|
||||
tokens::{AccessToken, RefreshToken, TokenFormatError, TokenType},
|
||||
traits::{StorageBackend, StorageBackendMarker},
|
||||
users::{Authentication, BrowserSession, User},
|
||||
users::{Authentication, BrowserSession, User, UserEmail},
|
||||
};
|
||||
|
@ -16,6 +16,7 @@ pub trait StorageBackendMarker: StorageBackend {}
|
||||
|
||||
pub trait StorageBackend {
|
||||
type UserData: Clone + std::fmt::Debug + PartialEq;
|
||||
type UserEmailData: Clone + std::fmt::Debug + PartialEq;
|
||||
type AuthenticationData: Clone + std::fmt::Debug + PartialEq;
|
||||
type BrowserSessionData: Clone + std::fmt::Debug + PartialEq;
|
||||
type ClientData: Clone + std::fmt::Debug + PartialEq;
|
||||
@ -34,4 +35,5 @@ impl StorageBackend for () {
|
||||
type RefreshTokenData = ();
|
||||
type SessionData = ();
|
||||
type UserData = ();
|
||||
type UserEmailData = ();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ pub struct User<T: StorageBackend> {
|
||||
pub data: T::UserData,
|
||||
pub username: String,
|
||||
pub sub: String,
|
||||
pub primary_email: Option<UserEmail<T>>,
|
||||
}
|
||||
|
||||
impl<T: StorageBackend> User<T>
|
||||
@ -36,6 +37,7 @@ where
|
||||
data: Default::default(),
|
||||
username: "john".to_string(),
|
||||
sub: "123-456".to_string(),
|
||||
primary_email: None,
|
||||
}]
|
||||
}
|
||||
}
|
||||
@ -46,6 +48,7 @@ impl<S: StorageBackendMarker> From<User<S>> for User<()> {
|
||||
data: (),
|
||||
username: u.username,
|
||||
sub: u.sub,
|
||||
primary_email: u.primary_email.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,3 +109,47 @@ where
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(bound = "T: StorageBackend")]
|
||||
pub struct UserEmail<T: StorageBackend> {
|
||||
#[serde(skip_serializing)]
|
||||
pub data: T::UserEmailData,
|
||||
pub email: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub confirmed_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl<S: StorageBackendMarker> From<UserEmail<S>> for UserEmail<()> {
|
||||
fn from(e: UserEmail<S>) -> Self {
|
||||
UserEmail {
|
||||
data: (),
|
||||
email: e.email,
|
||||
created_at: e.created_at,
|
||||
confirmed_at: e.confirmed_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: StorageBackend> UserEmail<T>
|
||||
where
|
||||
T::UserEmailData: Default,
|
||||
{
|
||||
#[must_use]
|
||||
pub fn samples() -> Vec<Self> {
|
||||
vec![
|
||||
UserEmail {
|
||||
data: T::UserEmailData::default(),
|
||||
email: "alice@example.com".to_string(),
|
||||
created_at: Utc::now(),
|
||||
confirmed_at: Some(Utc::now()),
|
||||
},
|
||||
UserEmail {
|
||||
data: T::UserEmailData::default(),
|
||||
email: "bob@example.com".to_string(),
|
||||
created_at: Utc::now(),
|
||||
confirmed_at: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user