fix: username and community title validation
This commit is contained in:
parent
a4d7f44aa3
commit
efb259764e
7 changed files with 79 additions and 25 deletions
|
@ -128,14 +128,15 @@ impl DataManager {
|
|||
return Err(Error::MiscError("This username cannot be used".to_string()));
|
||||
}
|
||||
|
||||
if data.username.contains(" ") {
|
||||
return Err(Error::MiscError("Name cannot contain spaces".to_string()));
|
||||
} else if data.username.contains("%") {
|
||||
return Err(Error::MiscError("Name cannot contain \"%\"".to_string()));
|
||||
} else if data.username.contains("?") {
|
||||
return Err(Error::MiscError("Name cannot contain \"?\"".to_string()));
|
||||
} else if data.username.contains("&") {
|
||||
return Err(Error::MiscError("Name cannot contain \"&\"".to_string()));
|
||||
let regex = regex::RegexBuilder::new(r"[^\w_\-\.!]+")
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
if regex.captures(&data.username).is_some() {
|
||||
return Err(Error::MiscError(
|
||||
"This username contains invalid characters".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// make sure username isn't taken
|
||||
|
@ -436,6 +437,29 @@ impl DataManager {
|
|||
}
|
||||
|
||||
pub async fn update_user_username(&self, id: usize, to: String, user: User) -> Result<()> {
|
||||
// check value
|
||||
if to.len() < 2 {
|
||||
return Err(Error::DataTooShort("username".to_string()));
|
||||
} else if to.len() > 32 {
|
||||
return Err(Error::DataTooLong("username".to_string()));
|
||||
}
|
||||
|
||||
if self.0.banned_usernames.contains(&to) {
|
||||
return Err(Error::MiscError("This username cannot be used".to_string()));
|
||||
}
|
||||
|
||||
let regex = regex::RegexBuilder::new(r"[^\w_\-\.!]+")
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
if regex.captures(&to).is_some() {
|
||||
return Err(Error::MiscError(
|
||||
"This username contains invalid characters".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue