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
data-model: have more structs use a state machine
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
use anyhow::Context as _;
|
||||
use async_graphql::{Context, Description, Object, ID};
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_data_model::CompatSsoLoginState;
|
||||
use mas_storage::{user::UserRepository, Repository};
|
||||
use sqlx::PgPool;
|
||||
use url::Url;
|
||||
@ -57,7 +56,7 @@ impl CompatSession {
|
||||
|
||||
/// When the session ended.
|
||||
pub async fn finished_at(&self) -> Option<DateTime<Utc>> {
|
||||
self.0.finished_at
|
||||
self.0.finished_at()
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,29 +85,16 @@ impl CompatSsoLogin {
|
||||
/// When the login was fulfilled, and the user was redirected back to the
|
||||
/// client.
|
||||
async fn fulfilled_at(&self) -> Option<DateTime<Utc>> {
|
||||
match &self.0.state {
|
||||
CompatSsoLoginState::Pending => None,
|
||||
CompatSsoLoginState::Fulfilled { fulfilled_at, .. }
|
||||
| CompatSsoLoginState::Exchanged { fulfilled_at, .. } => Some(*fulfilled_at),
|
||||
}
|
||||
self.0.fulfilled_at()
|
||||
}
|
||||
|
||||
/// When the client exchanged the login token sent during the redirection.
|
||||
async fn exchanged_at(&self) -> Option<DateTime<Utc>> {
|
||||
match &self.0.state {
|
||||
CompatSsoLoginState::Pending | CompatSsoLoginState::Fulfilled { .. } => None,
|
||||
CompatSsoLoginState::Exchanged { exchanged_at, .. } => Some(*exchanged_at),
|
||||
}
|
||||
self.0.exchanged_at()
|
||||
}
|
||||
|
||||
/// The compat session which was started by this login.
|
||||
async fn session(&self) -> Option<CompatSession> {
|
||||
match &self.0.state {
|
||||
CompatSsoLoginState::Pending => None,
|
||||
CompatSsoLoginState::Fulfilled { session, .. }
|
||||
| CompatSsoLoginState::Exchanged { session, .. } => {
|
||||
Some(CompatSession(session.clone()))
|
||||
}
|
||||
}
|
||||
self.0.session().cloned().map(CompatSession)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user