-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e50c851
commit c1ab497
Showing
4 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,17 @@ | |
PasswordResetTokenInvalidError, | ||
SignUpPostNotAllowedResponse, | ||
SignUpPostOkResult, | ||
UnknownUserIdError, | ||
) | ||
from supertokens_python.recipe.emailpassword.types import ( | ||
EmailDeliveryOverrideInput, | ||
EmailTemplateVars, | ||
FormField, | ||
) | ||
from supertokens_python.recipe.emailverification.interfaces import ( | ||
EmailDoesNotExistError, | ||
GetEmailForUserIdOkResult, | ||
) | ||
from supertokens_python.recipe.session import SessionContainer | ||
from supertokens_python.recipe.thirdparty.provider import RedirectUriInfo | ||
from supertokens_python.recipe.thirdparty.types import ( | ||
|
@@ -47,6 +52,39 @@ def func(*args): # type: ignore | |
|
||
return func # type: ignore | ||
|
||
elif eval_str.startswith("emailverification.init.emailDelivery.override"): | ||
from supertokens_python.recipe.emailverification.types import ( | ||
EmailDeliveryOverrideInput as EVEmailDeliveryOverrideInput, | ||
EmailTemplateVars as EVEmailTemplateVars, | ||
) | ||
|
||
def custom_email_delivery_override( | ||
original_implementation: EVEmailDeliveryOverrideInput, | ||
) -> EVEmailDeliveryOverrideInput: | ||
original_send_email = original_implementation.send_email | ||
|
||
async def send_email( | ||
template_vars: EVEmailTemplateVars, user_context: Dict[str, Any] | ||
) -> None: | ||
global userInCallback # pylint: disable=global-variable-not-assigned | ||
global token # pylint: disable=global-variable-not-assigned | ||
|
||
if template_vars.user: | ||
userInCallback = template_vars.user | ||
|
||
if template_vars.email_verify_link: | ||
token = template_vars.email_verify_link.split("?token=")[1].split( | ||
"&tenantId=" | ||
)[0] | ||
|
||
# Call the original implementation | ||
await original_send_email(template_vars, user_context) | ||
|
||
original_implementation.send_email = send_email | ||
return original_implementation | ||
|
||
return custom_email_delivery_override | ||
|
||
elif eval_str.startswith("emailpassword.init.emailDelivery.override"): | ||
|
||
def custom_email_deliver( | ||
|
@@ -500,6 +538,27 @@ async def get_user_info5( | |
|
||
return custom_provider | ||
|
||
if eval_str.startswith("emailverification.init.getEmailForRecipeUserId"): | ||
|
||
async def get_email_for_recipe_user_id( | ||
recipe_user_id: RecipeUserId, | ||
user_context: Dict[str, Any], | ||
) -> Union[ | ||
GetEmailForUserIdOkResult, EmailDoesNotExistError, UnknownUserIdError | ||
]: | ||
if "[email protected]" in eval_str: | ||
return GetEmailForUserIdOkResult(email="[email protected]") | ||
|
||
if ( | ||
hasattr(recipe_user_id, "get_as_string") | ||
and recipe_user_id.get_as_string() == "random" | ||
): | ||
return GetEmailForUserIdOkResult(email="[email protected]") | ||
|
||
return UnknownUserIdError() | ||
|
||
return get_email_for_recipe_user_id | ||
|
||
raise Exception("Unknown eval string: " + eval_str) | ||
|
||
|
||
|