]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/user/create.rs
Making community_follower.pending column not null.
[lemmy.git] / crates / api_crud / src / user / create.rs
index 06b576e51a46c81d0aec209a8fd56cb58c47bd86..6752dcc84344059f217b40c0c25a136be1742107 100644 (file)
@@ -1,11 +1,8 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  blocking,
-  honeypot_check,
-  password_length_check,
-  person::*,
-  send_verification_email,
+  person::{LoginResponse, Register},
+  utils::{blocking, honeypot_check, password_length_check, send_verification_email},
 };
 use lemmy_apub::{
   generate_followers_url,
@@ -15,6 +12,7 @@ use lemmy_apub::{
   EndpointType,
 };
 use lemmy_db_schema::{
+  aggregates::structs::PersonAggregates,
   newtypes::CommunityId,
   source::{
     community::{
@@ -32,7 +30,8 @@ use lemmy_db_schema::{
   },
   traits::{Crud, Followable, Joinable},
 };
-use lemmy_db_views_actor::person_view::PersonViewSafe;
+use lemmy_db_views::structs::LocalUserView;
+use lemmy_db_views_actor::structs::PersonViewSafe;
 use lemmy_utils::{
   apub::generate_actor_keypair,
   claims::Claims,
@@ -141,8 +140,7 @@ impl PerformCrud for Register {
       Person::create(conn, &person_form)
     })
     .await?
-    .map_err(LemmyError::from)
-    .map_err(|e| e.with_message("user_already_exists"))?;
+    .map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
 
     // Create the local user
     let local_user_form = LocalUserForm {
@@ -175,7 +173,7 @@ impl PerformCrud for Register {
         })
         .await??;
 
-        return Err(LemmyError::from(e).with_message(err_type));
+        return Err(LemmyError::from_error_message(e, err_type));
       }
     };
 
@@ -234,14 +232,13 @@ impl PerformCrud for Register {
     let community_follower_form = CommunityFollowerForm {
       community_id: main_community.id,
       person_id: inserted_person.id,
-      pending: false,
+      pending: Some(false),
     };
 
     let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
     blocking(context.pool(), follow)
       .await?
-      .map_err(LemmyError::from)
-      .map_err(|e| e.with_message("community_follower_already_exists"))?;
+      .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
 
     // If its an admin, add them as a mod and follower to main
     if no_admins {
@@ -253,8 +250,7 @@ impl PerformCrud for Register {
       let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
       blocking(context.pool(), join)
         .await?
-        .map_err(LemmyError::from)
-        .map_err(|e| e.with_message("community_moderator_already_exists"))?;
+        .map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
     }
 
     let mut login_response = LoginResponse {
@@ -275,11 +271,20 @@ impl PerformCrud for Register {
       );
     } else {
       if email_verification {
+        let local_user_view = LocalUserView {
+          local_user: inserted_local_user,
+          person: inserted_person,
+          counts: PersonAggregates::default(),
+        };
+        // we check at the beginning of this method that email is set
+        let email = local_user_view
+          .local_user
+          .email
+          .clone()
+          .expect("email was provided");
         send_verification_email(
-          inserted_local_user.id,
-          // we check at the beginning of this method that email is set
-          &inserted_local_user.email.expect("email was provided"),
-          &inserted_person.name,
+          &local_user_view,
+          &email,
           context.pool(),
           &context.settings(),
         )