mas_data_model/site_config.rs
1// Copyright 2024 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use chrono::Duration;
8use url::Url;
9
10/// Which Captcha service is being used
11#[derive(Debug, Clone, Copy)]
12pub enum CaptchaService {
13 RecaptchaV2,
14 CloudflareTurnstile,
15 HCaptcha,
16}
17
18/// Captcha configuration
19#[derive(Debug, Clone)]
20pub struct CaptchaConfig {
21 /// Which Captcha service is being used
22 pub service: CaptchaService,
23
24 /// The site key used by the instance
25 pub site_key: String,
26
27 /// The secret key used by the instance
28 pub secret_key: String,
29}
30
31/// Automatic session expiration configuration
32#[derive(Debug, Clone)]
33pub struct SessionExpirationConfig {
34 pub user_session_inactivity_ttl: Option<Duration>,
35 pub oauth_session_inactivity_ttl: Option<Duration>,
36 pub compat_session_inactivity_ttl: Option<Duration>,
37}
38
39/// Random site configuration we want accessible in various places.
40#[allow(clippy::struct_excessive_bools)]
41#[derive(Debug, Clone)]
42pub struct SiteConfig {
43 /// Time-to-live of access tokens.
44 pub access_token_ttl: Duration,
45
46 /// Time-to-live of compatibility access tokens.
47 pub compat_token_ttl: Duration,
48
49 /// The server name, e.g. "matrix.org".
50 pub server_name: String,
51
52 /// The URL to the privacy policy.
53 pub policy_uri: Option<Url>,
54
55 /// The URL to the terms of service.
56 pub tos_uri: Option<Url>,
57
58 /// Imprint to show in the footer.
59 pub imprint: Option<String>,
60
61 /// Whether password login is enabled.
62 pub password_login_enabled: bool,
63
64 /// Whether password registration is enabled.
65 pub password_registration_enabled: bool,
66
67 /// Whether users can change their email.
68 pub email_change_allowed: bool,
69
70 /// Whether users can change their display name.
71 pub displayname_change_allowed: bool,
72
73 /// Whether users can change their password.
74 pub password_change_allowed: bool,
75
76 /// Whether users can recover their account via email.
77 pub account_recovery_allowed: bool,
78
79 /// Whether users can delete their own account.
80 pub account_deactivation_allowed: bool,
81
82 /// Captcha configuration
83 pub captcha: Option<CaptchaConfig>,
84
85 /// Minimum password complexity, between 0 and 4.
86 /// This is a score from zxcvbn.
87 pub minimum_password_complexity: u8,
88
89 pub session_expiration: Option<SessionExpirationConfig>,
90}