1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

Make password-based login optional

This commit is contained in:
Quentin Gliech
2023-05-23 14:20:27 +02:00
parent 25f045130e
commit d2d68e9a27
16 changed files with 572 additions and 118 deletions

View File

@ -286,6 +286,7 @@ pub struct PostAuthContext {
pub struct LoginContext {
form: FormState<LoginFormField>,
next: Option<PostAuthContext>,
password_disabled: bool,
providers: Vec<UpstreamOAuthProvider>,
}
@ -295,15 +296,33 @@ impl TemplateContext for LoginContext {
Self: Sized,
{
// TODO: samples with errors
vec![LoginContext {
form: FormState::default(),
next: None,
providers: Vec::new(),
}]
vec![
LoginContext {
form: FormState::default(),
next: None,
password_disabled: true,
providers: Vec::new(),
},
LoginContext {
form: FormState::default(),
next: None,
password_disabled: false,
providers: Vec::new(),
},
]
}
}
impl LoginContext {
/// Set whether password login is enabled or not
#[must_use]
pub fn with_password_login(self, enabled: bool) -> Self {
Self {
password_disabled: !enabled,
..self
}
}
/// Set the form state
#[must_use]
pub fn with_form_state(self, form: FormState<LoginFormField>) -> Self {
@ -312,7 +331,7 @@ impl LoginContext {
/// Set the upstream OAuth 2.0 providers
#[must_use]
pub fn with_upstrem_providers(self, providers: Vec<UpstreamOAuthProvider>) -> Self {
pub fn with_upstream_providers(self, providers: Vec<UpstreamOAuthProvider>) -> Self {
Self { providers, ..self }
}

View File

@ -31,6 +31,7 @@ use camino::{Utf8Path, Utf8PathBuf};
use mas_router::UrlBuilder;
use rand::Rng;
use serde::Serialize;
pub use tera::escape_html;
use tera::{Context, Error as TeraError, Tera};
use thiserror::Error;
use tokio::{sync::RwLock, task::JoinError};