jwt_secret: "changeme"
# The dir for the front end
front_end_dir: "/app/dist"
- # whether to enable activitypub federation. this feature is in alpha, do not enable in production, as might
- # cause problems like remote instances fetching and permanently storing bad data.
- federation_enabled: false
# rate limits for various user actions, by user ip
rate_limit: {
# maximum number of messages created in interval
use super::*;
+use crate::is_valid_username;
use bcrypt::verify;
#[derive(Serialize, Deserialize, Debug)]
return Err(APIError::err("admin_already_created").into());
}
+ if !is_valid_username(&data.username) {
+ return Err(APIError::err("invalid_username").into());
+ }
+
// Register the new user
let user_form = UserForm {
name: data.username.to_owned(),
.to_string()
}
+pub fn is_valid_username(name: &str) -> bool {
+ VALID_USERNAME_REGEX.is_match(name)
+}
+
#[cfg(test)]
mod tests {
use crate::{
- extract_usernames, is_email_regex, is_image_content_type, remove_slurs, slur_check,
- slurs_vec_to_str,
+ extract_usernames, is_email_regex, is_image_content_type, is_valid_username, remove_slurs,
+ slur_check, slurs_vec_to_str,
};
#[test]
assert!(!is_email_regex("nada_neutho"));
}
+ #[test]
+ fn test_valid_register_username() {
+ assert!(is_valid_username("Hello_98"));
+ assert!(is_valid_username("ten"));
+ assert!(!is_valid_username("Hello-98"));
+ assert!(!is_valid_username("a"));
+ assert!(!is_valid_username(""));
+ }
+
#[test]
fn test_slur_filter() {
let test =
static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
static ref SLUR_REGEX: Regex = RegexBuilder::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|nig(\b|g?(a|er)?(s|z)?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btrann?(y|ies?)|ladyboy(s?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap();
static ref USERNAME_MATCHES_REGEX: Regex = Regex::new(r"/u/[a-zA-Z][0-9a-zA-Z_]*").unwrap();
+ static ref VALID_USERNAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,20}$").unwrap();
}
Ok(site_view) => site_view,
Err(_) => return Err(format_err!("not_found")),
};
- let protocols = if Settings::get().federation_enabled {
- vec!["activitypub".to_string()]
- } else {
- vec![]
- };
+ let protocols = vec![];
Ok(NodeInfo {
version: "2.0".to_string(),
software: NodeInfoSoftware {
}
pub fn config(cfg: &mut web::ServiceConfig) {
- if Settings::get().federation_enabled {
- cfg.route(
- ".well-known/webfinger",
- web::get().to(get_webfinger_response),
- );
- }
+ cfg.route(
+ ".well-known/webfinger",
+ web::get().to(get_webfinger_response),
+ );
}
lazy_static! {
pub front_end_dir: String,
pub rate_limit: RateLimitConfig,
pub email: Option<EmailConfig>,
- pub federation_enabled: bool,
}
#[derive(Debug, Deserialize, Clone)]
.new-comments {
max-height: 50vh;
- overflow: hidden;
-}
-
-.new-comments:hover {
+ overflow-x: hidden;
overflow-y: auto;
}
<form>
<label
htmlFor="file-upload"
- className={`${UserService.Instance.user &&
- 'pointer'} d-inline-block float-right text-muted font-weight-bold`}
+ className={`${
+ UserService.Instance.user && 'pointer'
+ } d-inline-block float-right text-muted font-weight-bold`}
data-tippy-content={i18n.t('upload_image')}
>
<svg class="icon icon-inline">
)}
{this.state.postForm.body && (
<button
- className={`mt-1 mr-2 btn btn-sm btn-secondary ${this.state
- .previewMode && 'active'}`}
+ className={`mt-1 mr-2 btn btn-sm btn-secondary ${
+ this.state.previewMode && 'active'
+ }`}
onClick={linkEvent(this, this.handlePreviewToggle)}
>
{i18n.t('preview')}
value={this.state.postForm.community_id}
onInput={linkEvent(this, this.handlePostCommunityChange)}
>
+ <option>{i18n.t('select_a_community')}</option>
{this.state.communities.map(community => (
<option value={community.id}>{community.name}</option>
))}
)}
<div class="form-group row">
<div class="col-sm-10">
- <button type="submit" class="btn btn-secondary mr-2">
+ <button
+ disabled={!this.state.postForm.community_id}
+ type="submit"
+ class="btn btn-secondary mr-2"
+ >
{this.state.loading ? (
<svg class="icon icon-spinner spin">
<use xlinkHref="#icon-spinner"></use>
).id;
this.state.postForm.community_id = foundCommunityId;
} else {
- this.state.postForm.community_id = data.communities[0].id;
+ // By default, the null valued 'Select a Community'
}
this.setState(this.state);
let selector = new Selectr(selectId, { nativeDropdown: false });
selector.on('selectr.select', option => {
this.state.postForm.community_id = Number(option.value);
+ this.setState(this.state);
});
}
} else if (res.op == UserOperation.CreatePost) {
"communities": "Communities",
"users": "Users",
"create_a_community": "Create a community",
+ "select_a_community": "Select a community",
"create_community": "Create Community",
"remove_community": "Remove Community",
"subscribed_to_communities": "Subscribed to <1>communities</1>",
"sponsors": "Sponsors",
"sponsors_of_lemmy": "Sponsors of Lemmy",
"sponsor_message":
- "Lemmy is free, <1>open-source</1> software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:",
+ "Lemmy is free, <1>open-source</1> software, with no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:",
"support_on_patreon": "Support on Patreon",
"support_on_liberapay": "Support on Liberapay",
"support_on_open_collective": "Support on OpenCollective",
"Couldn't find that username or email.",
"password_incorrect": "Password incorrect.",
"passwords_dont_match": "Passwords do not match.",
+ "invalid_username": "Invalid username.",
"admin_already_created": "Sorry, there's already an admin.",
"user_already_exists": "User already exists.",
"email_already_exists": "Email already exists.",