- blocking(context.pool(), move |conn| {
- Person::update(conn, person_id, &person_form)
- })
- .await?
- .map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
-
- let local_user_form = LocalUserForm {
- person_id: Some(person_id),
- email,
- password_encrypted: Some(password_encrypted),
- show_nsfw: data.show_nsfw,
- show_bot_accounts: data.show_bot_accounts,
- show_scores: data.show_scores,
- theme: data.theme.to_owned(),
- default_sort_type,
- default_listing_type,
- lang: data.lang.to_owned(),
- show_avatars: data.show_avatars,
- show_read_posts: data.show_read_posts,
- show_new_post_notifs: data.show_new_post_notifs,
- send_notifications_to_email: data.send_notifications_to_email,
- email_verified: None,
- accepted_application: None,
+ // If generate_totp is Some(false), this will clear it out from the database.
+ let (totp_2fa_secret, totp_2fa_url) = if let Some(generate) = data.generate_totp_2fa {
+ if generate {
+ let secret = generate_totp_2fa_secret();
+ let url =
+ build_totp_2fa(&site_view.site.name, &local_user_view.person.name, &secret)?.get_url();
+ (Some(Some(secret)), Some(Some(url)))
+ } else {
+ (Some(None), Some(None))
+ }
+ } else {
+ (None, None)