Documentation
This commit is contained in:
parent
63266dec56
commit
bb9a6ba9ec
5 changed files with 47 additions and 18 deletions
|
|
@ -1,28 +1,56 @@
|
|||
use std::time::Duration;
|
||||
|
||||
/// 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_FILE: &str = "translation.ron";
|
||||
|
||||
/// Directory where the database is stored.
|
||||
/// It's located in the current directory.
|
||||
pub const DB_DIRECTORY: &str = "data";
|
||||
|
||||
/// 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";
|
||||
|
||||
/// 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).
|
||||
|
||||
pub const COOKIE_AUTH_TOKEN_NAME: &str = "auth_token";
|
||||
pub const COOKIE_LANG_NAME: &str = "lang";
|
||||
|
||||
/// 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).
|
||||
|
||||
// Number of alphanumeric characters for tokens
|
||||
// (cookie authentication, password reset, validation token).
|
||||
/// 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;
|
||||
|
||||
/// 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').
|
||||
pub const REVERSE_PROXY_IP_HTTP_FIELD: &str = "x-real-ip"; // Set by the reverse proxy (Nginx).
|
||||
/// 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";
|
||||
|
||||
pub const MAX_DB_CONNECTION: u32 = 1; // To avoid database lock.
|
||||
// To avoid database lock.
|
||||
pub const MAX_DB_CONNECTION: u32 = 1;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
//! A little cooking recipes website.
|
||||
|
||||
use std::{net::SocketAddr, path::Path};
|
||||
|
||||
use axum::{
|
||||
|
|
@ -86,10 +88,10 @@ const TRACING_LEVEL: tracing::Level = tracing::Level::DEBUG;
|
|||
const TRACING_LEVEL: tracing::Level = tracing::Level::INFO;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Context {
|
||||
pub user: Option<model::User>,
|
||||
pub tr: Tr,
|
||||
pub dark_theme: bool,
|
||||
struct Context {
|
||||
user: Option<model::User>,
|
||||
tr: Tr,
|
||||
dark_theme: bool,
|
||||
}
|
||||
|
||||
// TODO: Should main returns 'Result'?
|
||||
|
|
@ -360,8 +362,8 @@ fn url_rewriting(mut req: Request) -> Request {
|
|||
req
|
||||
}
|
||||
|
||||
/// The language of the current HTTP request is defined in the current order:
|
||||
/// - Extraction from the url: like in '/fr/recipe/view/42'
|
||||
/// The language associated to the current HTTP request is defined in the current order:
|
||||
/// - Extraction from the url: like in `/fr/recipe/view/42`
|
||||
/// - Get from the user database record.
|
||||
/// - Get from the cookie.
|
||||
/// - Get from the HTTP header `accept-language`.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ pub async fn edit(
|
|||
) -> Result<Response> {
|
||||
if let Some(ref user) = context.user {
|
||||
if let Some(recipe) = connection.get_recipe(recipe_id, false).await? {
|
||||
if model::can_user_edit_recipe(&user, &recipe) {
|
||||
if model::can_user_edit_recipe(user, &recipe) {
|
||||
let recipes = Recipes {
|
||||
published: connection
|
||||
.get_all_published_recipe_titles(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue