1 use crate::{captcha_as_wav_base64, Perform};
2 use actix_web::web::Data;
4 use captcha::{gen, Difficulty};
6 use lemmy_api_common::{
8 check_registration_application,
9 get_local_user_view_from_jwt,
11 password_length_check,
13 send_email_verification_success,
14 send_password_reset_email,
15 send_verification_email,
17 use lemmy_db_schema::{
18 diesel_option_overwrite,
19 diesel_option_overwrite_to_url,
20 from_opt_str_to_opt_enum,
25 email_verification::EmailVerification,
26 local_user::{LocalUser, LocalUserForm},
28 password_reset_request::*,
30 person_block::{PersonBlock, PersonBlockForm},
33 private_message::PrivateMessage,
36 traits::{Blockable, Crud},
40 comment_report_view::CommentReportView,
41 comment_view::{CommentQueryBuilder, CommentView},
42 local_user_view::LocalUserView,
43 post_report_view::PostReportView,
44 private_message_view::PrivateMessageView,
46 use lemmy_db_views_actor::{
47 community_moderator_view::CommunityModeratorView,
48 person_mention_view::{PersonMentionQueryBuilder, PersonMentionView},
49 person_view::PersonViewSafe,
53 utils::{is_valid_display_name, is_valid_matrix_id, naive_from_unix},
57 use lemmy_websocket::{
58 messages::{CaptchaItem, SendAllMessage},
63 #[async_trait::async_trait(?Send)]
64 impl Perform for Login {
65 type Response = LoginResponse;
67 #[tracing::instrument(skip(context, _websocket_id))]
70 context: &Data<LemmyContext>,
71 _websocket_id: Option<ConnectionId>,
72 ) -> Result<LoginResponse, LemmyError> {
73 let data: &Login = self;
75 // Fetch that username / email
76 let username_or_email = data.username_or_email.clone();
77 let local_user_view = blocking(context.pool(), move |conn| {
78 LocalUserView::find_by_email_or_name(conn, &username_or_email)
81 .map_err(LemmyError::from)
82 .map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
84 // Verify the password
85 let valid: bool = verify(
87 &local_user_view.local_user.password_encrypted,
91 return Err(LemmyError::from_message("password_incorrect"));
94 let site = blocking(context.pool(), Site::read_simple).await??;
95 if site.require_email_verification && !local_user_view.local_user.email_verified {
96 return Err(LemmyError::from_message("email_not_verified"));
99 check_registration_application(&site, &local_user_view, context.pool()).await?;
105 local_user_view.local_user.id.0,
106 &context.secret().jwt_secret,
107 &context.settings().hostname,
111 verify_email_sent: false,
112 registration_created: false,
117 #[async_trait::async_trait(?Send)]
118 impl Perform for GetCaptcha {
119 type Response = GetCaptchaResponse;
121 #[tracing::instrument(skip(context, _websocket_id))]
124 context: &Data<LemmyContext>,
125 _websocket_id: Option<ConnectionId>,
126 ) -> Result<Self::Response, LemmyError> {
127 let captcha_settings = context.settings().captcha;
129 if !captcha_settings.enabled {
130 return Ok(GetCaptchaResponse { ok: None });
133 let captcha = match captcha_settings.difficulty.as_str() {
134 "easy" => gen(Difficulty::Easy),
135 "medium" => gen(Difficulty::Medium),
136 "hard" => gen(Difficulty::Hard),
137 _ => gen(Difficulty::Medium),
140 let answer = captcha.chars_as_string();
142 let png = captcha.as_base64().expect("failed to generate captcha");
144 let uuid = uuid::Uuid::new_v4().to_string();
146 let wav = captcha_as_wav_base64(&captcha);
148 let captcha_item = CaptchaItem {
150 uuid: uuid.to_owned(),
151 expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
154 // Stores the captcha item on the queue
155 context.chat_server().do_send(captcha_item);
157 Ok(GetCaptchaResponse {
158 ok: Some(CaptchaResponse { png, wav, uuid }),
163 #[async_trait::async_trait(?Send)]
164 impl Perform for SaveUserSettings {
165 type Response = LoginResponse;
167 #[tracing::instrument(skip(context, _websocket_id))]
170 context: &Data<LemmyContext>,
171 _websocket_id: Option<ConnectionId>,
172 ) -> Result<LoginResponse, LemmyError> {
173 let data: &SaveUserSettings = self;
174 let local_user_view =
175 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
177 let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
178 let banner = diesel_option_overwrite_to_url(&data.banner)?;
179 let bio = diesel_option_overwrite(&data.bio);
180 let display_name = diesel_option_overwrite(&data.display_name);
181 let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id);
182 let bot_account = data.bot_account;
183 let email_deref = data.email.as_deref().map(|e| e.to_owned());
184 let email = diesel_option_overwrite(&email_deref);
186 if let Some(Some(email)) = &email {
187 let previous_email = local_user_view.local_user.email.unwrap_or_default();
188 // Only send the verification email if there was an email change
189 if previous_email.ne(email) {
190 send_verification_email(
191 local_user_view.local_user.id,
193 &local_user_view.person.name,
201 // When the site requires email, make sure email is not Some(None). IE, an overwrite to a None value
202 if let Some(email) = &email {
203 let site_fut = blocking(context.pool(), Site::read_simple);
204 if email.is_none() && site_fut.await??.require_email_verification {
205 return Err(LemmyError::from_message("email_required"));
209 if let Some(Some(bio)) = &bio {
210 if bio.chars().count() > 300 {
211 return Err(LemmyError::from_message("bio_length_overflow"));
215 if let Some(Some(display_name)) = &display_name {
216 if !is_valid_display_name(
218 context.settings().actor_name_max_length,
220 return Err(LemmyError::from_message("invalid_username"));
224 if let Some(Some(matrix_user_id)) = &matrix_user_id {
225 if !is_valid_matrix_id(matrix_user_id) {
226 return Err(LemmyError::from_message("invalid_matrix_id"));
230 let local_user_id = local_user_view.local_user.id;
231 let person_id = local_user_view.person.id;
232 let default_listing_type = data.default_listing_type;
233 let default_sort_type = data.default_sort_type;
234 let password_encrypted = local_user_view.local_user.password_encrypted;
235 let public_key = local_user_view.person.public_key;
237 let person_form = PersonForm {
238 name: local_user_view.person.name,
244 updated: Some(naive_now()),
253 last_refreshed_at: None,
254 shared_inbox_url: None,
260 blocking(context.pool(), move |conn| {
261 Person::update(conn, person_id, &person_form)
264 .map_err(LemmyError::from)
265 .map_err(|e| e.with_message("user_already_exists"))?;
267 let local_user_form = LocalUserForm {
268 person_id: Some(person_id),
270 password_encrypted: Some(password_encrypted),
271 show_nsfw: data.show_nsfw,
272 show_bot_accounts: data.show_bot_accounts,
273 show_scores: data.show_scores,
274 theme: data.theme.to_owned(),
276 default_listing_type,
277 lang: data.lang.to_owned(),
278 show_avatars: data.show_avatars,
279 show_read_posts: data.show_read_posts,
280 show_new_post_notifs: data.show_new_post_notifs,
281 send_notifications_to_email: data.send_notifications_to_email,
282 email_verified: None,
283 accepted_application: None,
286 let local_user_res = blocking(context.pool(), move |conn| {
287 LocalUser::update(conn, local_user_id, &local_user_form)
290 let updated_local_user = match local_user_res {
293 let err_type = if e.to_string()
294 == "duplicate key value violates unique constraint \"local_user_email_key\""
296 "email_already_exists"
298 "user_already_exists"
301 return Err(LemmyError::from(e).with_message(err_type));
309 updated_local_user.id.0,
310 &context.secret().jwt_secret,
311 &context.settings().hostname,
315 verify_email_sent: false,
316 registration_created: false,
321 #[async_trait::async_trait(?Send)]
322 impl Perform for ChangePassword {
323 type Response = LoginResponse;
325 #[tracing::instrument(skip(self, context, _websocket_id))]
328 context: &Data<LemmyContext>,
329 _websocket_id: Option<ConnectionId>,
330 ) -> Result<LoginResponse, LemmyError> {
331 let data: &ChangePassword = self;
332 let local_user_view =
333 get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
335 password_length_check(&data.new_password)?;
337 // Make sure passwords match
338 if data.new_password != data.new_password_verify {
339 return Err(LemmyError::from_message("passwords_dont_match"));
342 // Check the old password
343 let valid: bool = verify(
345 &local_user_view.local_user.password_encrypted,
349 return Err(LemmyError::from_message("password_incorrect"));
352 let local_user_id = local_user_view.local_user.id;
353 let new_password = data.new_password.to_owned();
354 let updated_local_user = blocking(context.pool(), move |conn| {
355 LocalUser::update_password(conn, local_user_id, &new_password)
363 updated_local_user.id.0,
364 &context.secret().jwt_secret,
365 &context.settings().hostname,
369 verify_email_sent: false,
370 registration_created: false,
375 #[async_trait::async_trait(?Send)]
376 impl Perform for AddAdmin {
377 type Response = AddAdminResponse;
379 #[tracing::instrument(skip(context, websocket_id))]
382 context: &Data<LemmyContext>,
383 websocket_id: Option<ConnectionId>,
384 ) -> Result<AddAdminResponse, LemmyError> {
385 let data: &AddAdmin = self;
386 let local_user_view =
387 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
389 // Make sure user is an admin
390 is_admin(&local_user_view)?;
392 let added = data.added;
393 let added_person_id = data.person_id;
394 let added_admin = blocking(context.pool(), move |conn| {
395 Person::add_admin(conn, added_person_id, added)
398 .map_err(LemmyError::from)
399 .map_err(|e| e.with_message("couldnt_update_user"))?;
402 let form = ModAddForm {
403 mod_person_id: local_user_view.person.id,
404 other_person_id: added_admin.id,
405 removed: Some(!data.added),
408 blocking(context.pool(), move |conn| ModAdd::create(conn, &form)).await??;
410 let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
412 let res = AddAdminResponse { admins };
414 context.chat_server().do_send(SendAllMessage {
415 op: UserOperation::AddAdmin,
416 response: res.clone(),
424 #[async_trait::async_trait(?Send)]
425 impl Perform for BanPerson {
426 type Response = BanPersonResponse;
428 #[tracing::instrument(skip(context, websocket_id))]
431 context: &Data<LemmyContext>,
432 websocket_id: Option<ConnectionId>,
433 ) -> Result<BanPersonResponse, LemmyError> {
434 let data: &BanPerson = self;
435 let local_user_view =
436 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
438 // Make sure user is an admin
439 is_admin(&local_user_view)?;
442 let banned_person_id = data.person_id;
443 let expires = data.expires.map(naive_from_unix);
445 let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban, expires);
446 blocking(context.pool(), ban_person)
448 .map_err(LemmyError::from)
449 .map_err(|e| e.with_message("couldnt_update_user"))?;
451 // Remove their data if that's desired
452 if data.remove_data.unwrap_or(false) {
454 blocking(context.pool(), move |conn: &'_ _| {
455 Post::update_removed_for_creator(conn, banned_person_id, None, true)
460 // Remove all communities where they're the top mod
461 // for now, remove the communities manually
462 let first_mod_communities = blocking(context.pool(), move |conn: &'_ _| {
463 CommunityModeratorView::get_community_first_mods(conn)
467 // Filter to only this banned users top communities
468 let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
470 .filter(|fmc| fmc.moderator.id == banned_person_id)
473 for first_mod_community in banned_user_first_communities {
474 blocking(context.pool(), move |conn: &'_ _| {
475 Community::update_removed(conn, first_mod_community.community.id, true)
481 blocking(context.pool(), move |conn: &'_ _| {
482 Comment::update_removed_for_creator(conn, banned_person_id, true)
488 let form = ModBanForm {
489 mod_person_id: local_user_view.person.id,
490 other_person_id: data.person_id,
491 reason: data.reason.to_owned(),
492 banned: Some(data.ban),
496 blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
498 let person_id = data.person_id;
499 let person_view = blocking(context.pool(), move |conn| {
500 PersonViewSafe::read(conn, person_id)
504 let res = BanPersonResponse {
509 context.chat_server().do_send(SendAllMessage {
510 op: UserOperation::BanPerson,
511 response: res.clone(),
519 #[async_trait::async_trait(?Send)]
520 impl Perform for GetBannedPersons {
521 type Response = BannedPersonsResponse;
525 context: &Data<LemmyContext>,
526 _websocket_id: Option<ConnectionId>,
527 ) -> Result<Self::Response, LemmyError> {
528 let data: &GetBannedPersons = self;
529 let local_user_view =
530 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
532 // Make sure user is an admin
533 is_admin(&local_user_view)?;
535 let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
537 let res = Self::Response { banned };
543 #[async_trait::async_trait(?Send)]
544 impl Perform for BlockPerson {
545 type Response = BlockPersonResponse;
547 #[tracing::instrument(skip(context, _websocket_id))]
550 context: &Data<LemmyContext>,
551 _websocket_id: Option<ConnectionId>,
552 ) -> Result<BlockPersonResponse, LemmyError> {
553 let data: &BlockPerson = self;
554 let local_user_view =
555 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
557 let target_id = data.person_id;
558 let person_id = local_user_view.person.id;
560 // Don't let a person block themselves
561 if target_id == person_id {
562 return Err(LemmyError::from_message("cant_block_yourself"));
565 let person_block_form = PersonBlockForm {
571 let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
572 blocking(context.pool(), block)
574 .map_err(LemmyError::from)
575 .map_err(|e| e.with_message("person_block_already_exists"))?;
577 let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
578 blocking(context.pool(), unblock)
580 .map_err(LemmyError::from)
581 .map_err(|e| e.with_message("person_block_already_exists"))?;
584 // TODO does any federated stuff need to be done here?
586 let person_view = blocking(context.pool(), move |conn| {
587 PersonViewSafe::read(conn, target_id)
591 let res = BlockPersonResponse {
600 #[async_trait::async_trait(?Send)]
601 impl Perform for GetReplies {
602 type Response = GetRepliesResponse;
604 #[tracing::instrument(skip(context, _websocket_id))]
607 context: &Data<LemmyContext>,
608 _websocket_id: Option<ConnectionId>,
609 ) -> Result<GetRepliesResponse, LemmyError> {
610 let data: &GetReplies = self;
611 let local_user_view =
612 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
614 let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
616 let page = data.page;
617 let limit = data.limit;
618 let unread_only = data.unread_only;
619 let person_id = local_user_view.person.id;
620 let show_bot_accounts = local_user_view.local_user.show_bot_accounts;
622 let replies = blocking(context.pool(), move |conn| {
623 CommentQueryBuilder::create(conn)
625 .unread_only(unread_only)
626 .recipient_id(person_id)
627 .show_bot_accounts(show_bot_accounts)
628 .my_person_id(person_id)
635 Ok(GetRepliesResponse { replies })
639 #[async_trait::async_trait(?Send)]
640 impl Perform for GetPersonMentions {
641 type Response = GetPersonMentionsResponse;
643 #[tracing::instrument(skip(context, _websocket_id))]
646 context: &Data<LemmyContext>,
647 _websocket_id: Option<ConnectionId>,
648 ) -> Result<GetPersonMentionsResponse, LemmyError> {
649 let data: &GetPersonMentions = self;
650 let local_user_view =
651 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
653 let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
655 let page = data.page;
656 let limit = data.limit;
657 let unread_only = data.unread_only;
658 let person_id = local_user_view.person.id;
659 let mentions = blocking(context.pool(), move |conn| {
660 PersonMentionQueryBuilder::create(conn)
661 .recipient_id(person_id)
662 .my_person_id(person_id)
664 .unread_only(unread_only)
671 Ok(GetPersonMentionsResponse { mentions })
675 #[async_trait::async_trait(?Send)]
676 impl Perform for MarkPersonMentionAsRead {
677 type Response = PersonMentionResponse;
679 #[tracing::instrument(skip(context, _websocket_id))]
682 context: &Data<LemmyContext>,
683 _websocket_id: Option<ConnectionId>,
684 ) -> Result<PersonMentionResponse, LemmyError> {
685 let data: &MarkPersonMentionAsRead = self;
686 let local_user_view =
687 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
689 let person_mention_id = data.person_mention_id;
690 let read_person_mention = blocking(context.pool(), move |conn| {
691 PersonMention::read(conn, person_mention_id)
695 if local_user_view.person.id != read_person_mention.recipient_id {
696 return Err(LemmyError::from_message("couldnt_update_comment"));
699 let person_mention_id = read_person_mention.id;
700 let read = data.read;
702 move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
703 blocking(context.pool(), update_mention)
705 .map_err(LemmyError::from)
706 .map_err(|e| e.with_message("couldnt_update_comment"))?;
708 let person_mention_id = read_person_mention.id;
709 let person_id = local_user_view.person.id;
710 let person_mention_view = blocking(context.pool(), move |conn| {
711 PersonMentionView::read(conn, person_mention_id, Some(person_id))
715 Ok(PersonMentionResponse {
721 #[async_trait::async_trait(?Send)]
722 impl Perform for MarkAllAsRead {
723 type Response = GetRepliesResponse;
725 #[tracing::instrument(skip(context, _websocket_id))]
728 context: &Data<LemmyContext>,
729 _websocket_id: Option<ConnectionId>,
730 ) -> Result<GetRepliesResponse, LemmyError> {
731 let data: &MarkAllAsRead = self;
732 let local_user_view =
733 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
735 let person_id = local_user_view.person.id;
736 let replies = blocking(context.pool(), move |conn| {
737 CommentQueryBuilder::create(conn)
738 .my_person_id(person_id)
739 .recipient_id(person_id)
747 // TODO: this should probably be a bulk operation
748 // Not easy to do as a bulk operation,
749 // because recipient_id isn't in the comment table
750 for comment_view in &replies {
751 let reply_id = comment_view.comment.id;
752 let mark_as_read = move |conn: &'_ _| Comment::update_read(conn, reply_id, true);
753 blocking(context.pool(), mark_as_read)
755 .map_err(LemmyError::from)
756 .map_err(|e| e.with_message("couldnt_update_comment"))?;
759 // Mark all user mentions as read
760 let update_person_mentions =
761 move |conn: &'_ _| PersonMention::mark_all_as_read(conn, person_id);
762 blocking(context.pool(), update_person_mentions)
764 .map_err(LemmyError::from)
765 .map_err(|e| e.with_message("couldnt_update_comment"))?;
767 // Mark all private_messages as read
768 let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
769 blocking(context.pool(), update_pm)
771 .map_err(LemmyError::from)
772 .map_err(|e| e.with_message("couldnt_update_private_message"))?;
774 Ok(GetRepliesResponse { replies: vec![] })
778 #[async_trait::async_trait(?Send)]
779 impl Perform for PasswordReset {
780 type Response = PasswordResetResponse;
782 #[tracing::instrument(skip(self, context, _websocket_id))]
785 context: &Data<LemmyContext>,
786 _websocket_id: Option<ConnectionId>,
787 ) -> Result<PasswordResetResponse, LemmyError> {
788 let data: &PasswordReset = self;
791 let email = data.email.clone();
792 let local_user_view = blocking(context.pool(), move |conn| {
793 LocalUserView::find_by_email(conn, &email)
796 .map_err(LemmyError::from)
797 .map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
799 // Email the pure token to the user.
800 send_password_reset_email(&local_user_view, context.pool(), &context.settings()).await?;
801 Ok(PasswordResetResponse {})
805 #[async_trait::async_trait(?Send)]
806 impl Perform for PasswordChange {
807 type Response = LoginResponse;
809 #[tracing::instrument(skip(self, context, _websocket_id))]
812 context: &Data<LemmyContext>,
813 _websocket_id: Option<ConnectionId>,
814 ) -> Result<LoginResponse, LemmyError> {
815 let data: &PasswordChange = self;
817 // Fetch the user_id from the token
818 let token = data.token.clone();
819 let local_user_id = blocking(context.pool(), move |conn| {
820 PasswordResetRequest::read_from_token(conn, &token).map(|p| p.local_user_id)
824 password_length_check(&data.password)?;
826 // Make sure passwords match
827 if data.password != data.password_verify {
828 return Err(LemmyError::from_message("passwords_dont_match"));
831 // Update the user with the new password
832 let password = data.password.clone();
833 let updated_local_user = blocking(context.pool(), move |conn| {
834 LocalUser::update_password(conn, local_user_id, &password)
837 .map_err(LemmyError::from)
838 .map_err(|e| e.with_message("couldnt_update_user"))?;
844 updated_local_user.id.0,
845 &context.secret().jwt_secret,
846 &context.settings().hostname,
850 verify_email_sent: false,
851 registration_created: false,
856 #[async_trait::async_trait(?Send)]
857 impl Perform for GetReportCount {
858 type Response = GetReportCountResponse;
860 #[tracing::instrument(skip(context, _websocket_id))]
863 context: &Data<LemmyContext>,
864 _websocket_id: Option<ConnectionId>,
865 ) -> Result<GetReportCountResponse, LemmyError> {
866 let data: &GetReportCount = self;
867 let local_user_view =
868 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
870 let person_id = local_user_view.person.id;
871 let admin = local_user_view.person.admin;
872 let community_id = data.community_id;
874 let comment_reports = blocking(context.pool(), move |conn| {
875 CommentReportView::get_report_count(conn, person_id, admin, community_id)
879 let post_reports = blocking(context.pool(), move |conn| {
880 PostReportView::get_report_count(conn, person_id, admin, community_id)
884 let res = GetReportCountResponse {
894 #[async_trait::async_trait(?Send)]
895 impl Perform for GetUnreadCount {
896 type Response = GetUnreadCountResponse;
898 #[tracing::instrument(skip(context, _websocket_id))]
901 context: &Data<LemmyContext>,
902 _websocket_id: Option<ConnectionId>,
903 ) -> Result<Self::Response, LemmyError> {
905 let local_user_view =
906 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
908 let person_id = local_user_view.person.id;
910 let replies = blocking(context.pool(), move |conn| {
911 CommentView::get_unread_replies(conn, person_id)
915 let mentions = blocking(context.pool(), move |conn| {
916 PersonMentionView::get_unread_mentions(conn, person_id)
920 let private_messages = blocking(context.pool(), move |conn| {
921 PrivateMessageView::get_unread_messages(conn, person_id)
925 let res = Self::Response {
935 #[async_trait::async_trait(?Send)]
936 impl Perform for VerifyEmail {
937 type Response = VerifyEmailResponse;
941 context: &Data<LemmyContext>,
942 _websocket_id: Option<usize>,
943 ) -> Result<Self::Response, LemmyError> {
944 let token = self.token.clone();
945 let verification = blocking(context.pool(), move |conn| {
946 EmailVerification::read_for_token(conn, &token)
949 .map_err(LemmyError::from)
950 .map_err(|e| e.with_message("token_not_found"))?;
952 let form = LocalUserForm {
953 // necessary in case this is a new signup
954 email_verified: Some(true),
955 // necessary in case email of an existing user was changed
956 email: Some(Some(verification.email)),
957 ..LocalUserForm::default()
959 let local_user_id = verification.local_user_id;
960 blocking(context.pool(), move |conn| {
961 LocalUser::update(conn, local_user_id, &form)
965 let local_user_view = blocking(context.pool(), move |conn| {
966 LocalUserView::read(conn, local_user_id)
970 send_email_verification_success(&local_user_view, &context.settings())?;
972 blocking(context.pool(), move |conn| {
973 EmailVerification::delete_old_tokens_for_local_user(conn, local_user_id)
977 Ok(VerifyEmailResponse {})