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
Templates config
This commit is contained in:
@ -68,8 +68,8 @@ impl ServerCommand {
|
||||
queue.start();
|
||||
|
||||
// Load and compile the templates
|
||||
// TODO: custom template path from the config
|
||||
let templates = Templates::load(None, true).context("could not load templates")?;
|
||||
let templates =
|
||||
Templates::load_from_config(&config.templates).context("could not load templates")?;
|
||||
|
||||
// Start the server
|
||||
let root = mas_core::handlers::root(&pool, &templates, &config);
|
||||
|
@ -41,6 +41,10 @@ enum TemplatesSubcommand {
|
||||
Check {
|
||||
/// Path where the templates are
|
||||
path: String,
|
||||
|
||||
/// Skip loading builtin templates
|
||||
#[clap(long)]
|
||||
skip_builtin: bool,
|
||||
},
|
||||
}
|
||||
|
||||
@ -54,8 +58,8 @@ impl TemplatesCommand {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
SC::Check { path } => {
|
||||
Templates::load(Some(path.clone()), false)?;
|
||||
SC::Check { path, skip_builtin } => {
|
||||
Templates::load(Some(path), !skip_builtin)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ mod csrf;
|
||||
mod database;
|
||||
mod http;
|
||||
mod oauth2;
|
||||
mod templates;
|
||||
mod util;
|
||||
|
||||
pub use self::{
|
||||
@ -29,6 +30,7 @@ pub use self::{
|
||||
database::DatabaseConfig,
|
||||
http::HttpConfig,
|
||||
oauth2::{Algorithm, KeySet, OAuth2ClientConfig, OAuth2Config},
|
||||
templates::TemplatesConfig,
|
||||
util::ConfigurationSection,
|
||||
};
|
||||
|
||||
@ -44,6 +46,9 @@ pub struct RootConfig {
|
||||
|
||||
pub cookies: CookiesConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub templates: TemplatesConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub csrf: CsrfConfig,
|
||||
}
|
||||
@ -60,6 +65,7 @@ impl ConfigurationSection<'_> for RootConfig {
|
||||
http: HttpConfig::generate().await?,
|
||||
database: DatabaseConfig::generate().await?,
|
||||
cookies: CookiesConfig::generate().await?,
|
||||
templates: TemplatesConfig::generate().await?,
|
||||
csrf: CsrfConfig::generate().await?,
|
||||
})
|
||||
}
|
||||
@ -70,6 +76,7 @@ impl ConfigurationSection<'_> for RootConfig {
|
||||
http: HttpConfig::test(),
|
||||
database: DatabaseConfig::test(),
|
||||
cookies: CookiesConfig::test(),
|
||||
templates: TemplatesConfig::test(),
|
||||
csrf: CsrfConfig::test(),
|
||||
}
|
||||
}
|
||||
|
@ -90,12 +90,21 @@ struct FieldError<FieldType> {
|
||||
error: Box<dyn HtmlError>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct ErroredForm<FieldType> {
|
||||
form: Vec<FormError>,
|
||||
fields: Vec<FieldError<FieldType>>,
|
||||
}
|
||||
|
||||
impl<T> Default for ErroredForm<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
form: Vec::new(),
|
||||
fields: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ErroredForm<T> {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
|
@ -17,6 +17,7 @@
|
||||
use std::{collections::HashSet, io::Cursor, path::Path, string::ToString, sync::Arc};
|
||||
|
||||
use anyhow::Context as _;
|
||||
use mas_config::TemplatesConfig;
|
||||
use serde::Serialize;
|
||||
use tera::{Context, Error as TeraError, Tera};
|
||||
use thiserror::Error;
|
||||
@ -50,13 +51,18 @@ pub enum TemplateLoadingError {
|
||||
}
|
||||
|
||||
impl Templates {
|
||||
/// Load the templates from [the config][`TemplatesConfig`]
|
||||
pub fn load_from_config(config: &TemplatesConfig) -> Result<Self, TemplateLoadingError> {
|
||||
Self::load(config.path.as_deref(), config.builtin)
|
||||
}
|
||||
|
||||
/// Load the templates and check all needed templates are properly loaded
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `path` - An optional path to where templates should be loaded
|
||||
/// * `builtin` - Set to `true` to load the builtin templates as well
|
||||
pub fn load(path: Option<String>, builtin: bool) -> Result<Self, TemplateLoadingError> {
|
||||
pub fn load(path: Option<&str>, builtin: bool) -> Result<Self, TemplateLoadingError> {
|
||||
let tera = {
|
||||
let mut tera = Tera::default();
|
||||
|
||||
|
Reference in New Issue
Block a user