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:
parent
e52e86fc43
commit
cadc80c24f
@ -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")
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -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;
|
27
src/utils/virtual_directories_utils.rs
Normal file
27
src/utils/virtual_directories_utils.rs
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user