Skip to main content

mas_templates/context/
features.rs

1// Copyright 2025, 2026 Element Creations Ltd.
2// Copyright 2024, 2025 New Vector Ltd.
3// Copyright 2024 The Matrix.org Foundation C.I.C.
4//
5// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6// Please see LICENSE files in the repository root for full details.
7
8use std::sync::Arc;
9
10use minijinja::{
11    Value,
12    value::{Enumerator, Object},
13};
14
15/// Site features information.
16#[expect(clippy::struct_excessive_bools)]
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct SiteFeatures {
19    /// Whether local password-based registration is enabled.
20    pub password_registration: bool,
21
22    /// Whether local password-based registration requires an email address.
23    pub password_registration_email_required: bool,
24
25    /// Whether local password-based login is enabled.
26    pub password_login: bool,
27
28    /// Whether email-based account recovery is enabled.
29    pub account_recovery: bool,
30
31    /// Whether users can log in with their email address.
32    pub login_with_email_allowed: bool,
33
34    /// The minimum password complexity score required for new passwords.
35    pub minimum_password_complexity: u8,
36}
37
38impl Object for SiteFeatures {
39    fn get_value(self: &Arc<Self>, field: &Value) -> Option<Value> {
40        match field.as_str()? {
41            "password_registration" => Some(Value::from(self.password_registration)),
42            "password_registration_email_required" => {
43                Some(Value::from(self.password_registration_email_required))
44            }
45            "password_login" => Some(Value::from(self.password_login)),
46            "account_recovery" => Some(Value::from(self.account_recovery)),
47            "login_with_email_allowed" => Some(Value::from(self.login_with_email_allowed)),
48            "minimum_password_complexity" => Some(Value::from(self.minimum_password_complexity)),
49            _ => None,
50        }
51    }
52
53    fn enumerate(self: &Arc<Self>) -> Enumerator {
54        Enumerator::Str(&[
55            "password_registration",
56            "password_registration_email_required",
57            "password_login",
58            "account_recovery",
59            "login_with_email_allowed",
60            "minimum_password_complexity",
61        ])
62    }
63}