recipes/backend/src/consts.rs

63 lines
2.5 KiB
Rust

use std::time::Duration;
/// Current version of the application.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// The name of the configuration file.
/// it's located in the current directory.
pub const FILE_CONF: &str = "conf.ron";
/// The name of the translation file.
/// it's located in the current directory.
pub const TRANSLATION_DIR: &str = "translations";
/// Filename of the database.
/// It's located in the `DB_DIRECTORY` directory.
pub const DB_FILENAME: &str = "recipes.sqlite";
/// Path to the SQL file which contains the initial database schema.
pub const SQL_FILENAME: &str = "sql/version_{VERSION}.sql";
/// Base name for the log files, the date and the extension will be appended to it.
pub const BASE_LOG_FILENAME: &str = "recipes";
/// When a new user sign up, he has this duration to validate his account.
pub const VALIDATION_TOKEN_DURATION: i64 = 60 * 60; // [s]. (1 jour).
/// When an existing user reset his password, he has this duration to revalidate his account.
pub const VALIDATION_PASSWORD_RESET_TOKEN_DURATION: i64 = 60 * 60; // [s]. (1 jour).
/// The name of the cookie used for user authentication.
pub const COOKIE_AUTH_TOKEN_NAME: &str = "auth_token";
/// The name of the cookie for the current language.
/// Se here to know how the current language is defined: [crate::context].
pub const COOKIE_LANG_NAME: &str = "lang";
/// Number of alphanumeric characters for tokens
/// (cookie authentication, password reset, validation token).
pub const TOKEN_SIZE: usize = 32;
// TODO: Move it in conf.ron.
pub const EMAIL_ADDRESS: &str = "recipes@gburri.org";
/// When sending a validation email,
/// the server has this duration to wait for a response from the SMTP server.
pub const SEND_EMAIL_TIMEOUT: Duration = Duration::from_secs(60);
/// Some paths (like sign in, sign up, etc.) have a rate limit.
/// This is the number of requests allowed in a given time ([DURATION_FOR_RATE_LIMIT]).
pub const NUMBER_OF_CONCURRENT_HTTP_REQUEST_FOR_RATE_LIMIT: u64 = 10;
/// See [NUMBER_OF_CONCURRENT_HTTP_REQUEST_FOR_RATE_LIMIT].
pub const DURATION_FOR_RATE_LIMIT: Duration = Duration::from_secs(2);
/// HTTP headers, see <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers>.
/// Common headers can be found in `axum::http::header` (which is a re-export of the create 'http').
/// Set by the reverse proxy (nginx).
pub const REVERSE_PROXY_IP_HTTP_FIELD: &str = "x-real-ip";
// To avoid database lock.
pub const MAX_DB_CONNECTION: u32 = 1;
pub const NOT_AUTHORIZED_MESSAGE: &str = "Action not authorized";