1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 05:58:51 +00:00

Can get POST virtual directories

This commit is contained in:
Pierre HUBERT 2020-06-02 13:12:54 +02:00
parent e52e86fc43
commit cadc80c24f
4 changed files with 44 additions and 1 deletions

View File

@ -7,5 +7,8 @@ use crate::controllers::routes::RequestResult;
/// Find a user by its virtual directory
pub fn find_user(r: &mut HttpRequestHandler) -> RequestResult {
let directory = r.post_virtual_directory("subfolder")?;
r.success("implement it")
}

View File

@ -13,6 +13,7 @@ use crate::data::config::conf;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, user_helper};
use crate::utils::virtual_directories_utils::check_virtual_directory;
/// Http request handler
///
@ -321,4 +322,15 @@ impl HttpRequestHandler {
Ok(user_id)
}
/// Get a virtual directory included in a POST request
pub fn post_virtual_directory(&mut self, name: &str) -> ResultBoxError<String> {
let dir = self.post_string(name)?;
if !check_virtual_directory(&dir) {
self.bad_request(format!("Invalid virtual directory specified in '{}' !", name))?;
}
Ok(dir)
}
}

View File

@ -3,4 +3,5 @@
//! This module contains utilities that can be used anywhere in the code
pub mod crypt_utils;
pub mod user_data_utils;
pub mod user_data_utils;
pub mod virtual_directories_utils;

View File

@ -0,0 +1,27 @@
//! # Virtual directory utilities
//!
//! @author Pierre Hubert
/// Check out whether a virtual directory is valid or not
///
/// ```
/// use comunic_server::utils::virtual_directories_utils::check_virtual_directory;
///
/// assert_eq!(check_virtual_directory("ab"), false);
/// assert_eq!(check_virtual_directory("john"), true);
/// assert_eq!(check_virtual_directory("secret123"), true);
/// assert_eq!(check_virtual_directory("ab.php"), false);
/// ```
pub fn check_virtual_directory(dir: &str) -> bool {
if dir.len() < 4 || dir.len() > 30 {
return false;
}
for d in vec![".html", ".txt", ".php", "à", "â", "é", "ê", "@", "/", "\"", "'", "<", ">", "?", "&", "#"] {
if dir.contains(d) {
return false;
}
}
true
}