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,
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) {
name: data.username.to_owned(),
actor_id: Some(actor_id.clone()),
private_key: Some(Some(actor_keypair.private_key)),
- public_key: actor_keypair.public_key,
+ public_key: Some(actor_keypair.public_key),
inbox_url: Some(generate_inbox_url(&actor_id)?),
shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)),
admin: Some(no_admins),
// 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),
.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,
.email
.clone()
.expect("email was provided");
- send_verification_email(
- &local_user_view,
- &email,
- context.pool(),
- &context.settings(),
- )
- .await?;
+ send_verification_email(&local_user_view, &email, context.pool(), context.settings())
+ .await?;
login_response.verify_email_sent = true;
}