use actix_web::web::Data;
use lemmy_api_common::{
person::{LoginResponse, Register},
- utils::{blocking, honeypot_check, password_length_check, send_verification_email},
+ utils::{
+ blocking,
+ honeypot_check,
+ password_length_check,
+ send_new_applicant_email_to_admins,
+ send_verification_email,
+ },
};
use lemmy_apub::{
generate_inbox_url,
aggregates::structs::PersonAggregates,
source::{
local_user::{LocalUser, LocalUserForm},
- local_user_language::LocalUserLanguage,
person::{Person, PersonForm},
registration_application::{RegistrationApplication, RegistrationApplicationForm},
site::Site,
use lemmy_utils::{
claims::Claims,
error::LemmyError,
- utils::{check_slurs, is_valid_actor_name},
+ utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
ConnectionId,
};
use lemmy_websocket::{messages::CheckCaptcha, LemmyContext};
let (mut email_verification, mut require_application) = (false, false);
// Make sure site has open registration
- if let Ok(site) = blocking(context.pool(), Site::read_local_site).await? {
+ let site = blocking(context.pool(), Site::read_local).await?;
+ if let Ok(site) = &site {
if !site.open_registration {
return Err(LemmyError::from_message("registration_closed"));
}
}
}
- check_slurs(&data.username, &context.settings().slur_regex())?;
+ let slur_regex = &context.settings().slur_regex();
+ check_slurs(&data.username, slur_regex)?;
+ check_slurs_opt(&data.answer, slur_regex)?;
let actor_keypair = generate_actor_keypair()?;
if !is_valid_actor_name(&data.username, context.settings().actor_name_max_length) {
// Create the local user
let local_user_form = LocalUserForm {
person_id: Some(inserted_person.id),
- email: Some(data.email.as_deref().map(|s| s.to_owned())),
+ email: Some(data.email.as_deref().map(|s| s.to_lowercase())),
password_encrypted: Some(data.password.to_string()),
show_nsfw: Some(data.show_nsfw),
email_verified: Some(false),
if require_application {
// Create the registration application
let form = RegistrationApplicationForm {
- local_user_id: Some(local_user_id),
+ local_user_id: Some(inserted_local_user.id),
// We already made sure answer was not null above
answer: data.answer.to_owned(),
..RegistrationApplicationForm::default()
.await??;
}
+ // Email the admins
+ if site.map(|s| s.application_email_admins).unwrap_or(false) {
+ send_new_applicant_email_to_admins(&data.username, context.pool(), context.settings())
+ .await?;
+ }
+
let mut login_response = LoginResponse {
jwt: None,
registration_created: false,