|
73 | 73 | import io.supertokens.userroles.UserRoles; |
74 | 74 | import io.supertokens.utils.Utils; |
75 | 75 | import jakarta.servlet.ServletException; |
| 76 | +import org.jetbrains.annotations.NotNull; |
76 | 77 | import org.slf4j.Logger; |
77 | 78 | import org.slf4j.LoggerFactory; |
78 | 79 |
|
@@ -672,31 +673,45 @@ public static void createMultipleUserRoles(Main main, AppIdentifier appIdentifie |
672 | 673 | public static void verifyMultipleEmailForAllLoginMethods(AppIdentifier appIdentifier, Storage storage, |
673 | 674 | List<BulkImportUser> users) |
674 | 675 | throws StorageTransactionLogicException { |
675 | | - Map<String, String> emailToUserId = new HashMap<>(); |
676 | | - for (BulkImportUser user : users) { |
677 | | - for (LoginMethod lm : user.loginMethods) { |
678 | | - emailToUserId.put(lm.getSuperTokenOrExternalUserId(), lm.email); |
679 | | - } |
680 | | - } |
681 | 676 |
|
| 677 | + Map<String, String> emailToUserId = collectVerifiedEmailAddressesByUserIds(users); |
682 | 678 | try { |
683 | | - if(!emailToUserId.isEmpty()) { |
684 | | - EmailVerificationSQLStorage emailVerificationSQLStorage = StorageUtils |
685 | | - .getEmailVerificationStorage(storage); |
686 | | - emailVerificationSQLStorage.startTransaction(con -> { |
687 | | - emailVerificationSQLStorage |
688 | | - .updateMultipleIsEmailVerified_Transaction(appIdentifier, con, |
689 | | - emailToUserId, true); |
690 | | - |
691 | | - emailVerificationSQLStorage.commitTransaction(con); |
692 | | - return null; |
693 | | - }); |
694 | | - } |
| 679 | + verifyCollectedEmailAddressesForUsers(appIdentifier, storage, emailToUserId); |
695 | 680 | } catch (StorageQueryException e) { |
696 | 681 | throw new StorageTransactionLogicException(e); |
697 | 682 | } |
698 | 683 | } |
699 | 684 |
|
| 685 | + private static void verifyCollectedEmailAddressesForUsers(AppIdentifier appIdentifier, Storage storage, Map<String, String> emailToUserId) |
| 686 | + throws StorageQueryException, StorageTransactionLogicException { |
| 687 | + if(!emailToUserId.isEmpty()) { |
| 688 | + EmailVerificationSQLStorage emailVerificationSQLStorage = StorageUtils |
| 689 | + .getEmailVerificationStorage(storage); |
| 690 | + emailVerificationSQLStorage.startTransaction(con -> { |
| 691 | + emailVerificationSQLStorage |
| 692 | + .updateMultipleIsEmailVerified_Transaction(appIdentifier, con, |
| 693 | + emailToUserId, true); //only the verified email addresses are expected to be in the map |
| 694 | + |
| 695 | + emailVerificationSQLStorage.commitTransaction(con); |
| 696 | + return null; |
| 697 | + }); |
| 698 | + } |
| 699 | + } |
| 700 | + |
| 701 | + @NotNull |
| 702 | + private static Map<String, String> collectVerifiedEmailAddressesByUserIds(List<BulkImportUser> users) { |
| 703 | + Map<String, String> emailToUserId = new HashMap<>(); |
| 704 | + for (BulkImportUser user : users) { |
| 705 | + for (LoginMethod lm : user.loginMethods) { |
| 706 | + if(lm.isVerified) { |
| 707 | + //collect the verified email addresses for the userId |
| 708 | + emailToUserId.put(lm.getSuperTokenOrExternalUserId(), lm.email); |
| 709 | + } |
| 710 | + } |
| 711 | + } |
| 712 | + return emailToUserId; |
| 713 | + } |
| 714 | + |
700 | 715 | public static void createMultipleTotpDevices(Main main, AppIdentifier appIdentifier, |
701 | 716 | Storage storage, List<BulkImportUser> users) |
702 | 717 | throws StorageTransactionLogicException { |
|
0 commit comments