Skip to content

feat(session): Review based changes #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 12, 2022
14 changes: 14 additions & 0 deletions supertokens_python/post_init_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the
# "License") as published by the Apache Software Foundation.
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from typing import Callable, List


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from typing import Any, Dict

from supertokens_python.ingredients.emaildelivery.services.smtp import Transporter
from supertokens_python.ingredients.emaildelivery.types import (
EmailContent,
SMTPServiceInterface,
Expand All @@ -23,21 +22,9 @@
get_password_reset_email_content,
)
from supertokens_python.recipe.emailpassword.types import EmailTemplateVars
from supertokens_python.recipe.emailverification.emaildelivery.services.smtp.service_implementation import (
ServiceImplementation as EVServiceImplementation,
)


class ServiceImplementation(SMTPServiceInterface[EmailTemplateVars]):
def __init__(self, transporter: Transporter) -> None:
super().__init__(transporter)

email_verification_service_implementation = EVServiceImplementation(transporter)
self.ev_send_raw_email = (
email_verification_service_implementation.send_raw_email
)
self.ev_get_content = email_verification_service_implementation.get_content

async def send_raw_email(
self, content: EmailContent, user_context: Dict[str, Any]
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/recipe/emailpassword/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def handle_api_request(
)
if request_id == USER_PASSWORD_RESET:
return await handle_password_reset_api(self.api_implementation, api_options)
# FIXME: Should be False as per Node PR but the spec here don't allow it.

return None

async def handle_error(
Expand Down
2 changes: 1 addition & 1 deletion supertokens_python/recipe/emailverification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
from .emaildelivery import services as emaildelivery_services
from . import recipe
from .interfaces import TypeGetEmailForUserIdFunction
from .recipe import EmailVerificationRecipe
from .types import EmailTemplateVars, User
from ...ingredients.emaildelivery.types import EmailDeliveryConfig

InputOverrideConfig = utils.OverrideConfig
exception = ex
SMTPService = emaildelivery_services.SMTPService
EmailVerificationClaim = recipe.EmailVerificationClaim
EmailVerificationRecipe = recipe.EmailVerificationRecipe


if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def handle_email_verify_api(
)

result = await api_implementation.email_verify_post(
token, api_options, session, user_context
token, session, api_options, user_context
)
else:
if api_implementation.disable_is_email_verified_get:
Expand All @@ -63,9 +63,9 @@ async def handle_email_verify_api(
override_global_claim_validators=lambda _, __, ___: [],
user_context=user_context,
)

assert session is not None
result = await api_implementation.is_email_verified_get(
api_options, session, user_context
session, api_options, user_context
)

return send_200_response(result.to_json(), api_options.response)
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ async def handle_generate_email_verify_token_api(
assert session is not None

result = await api_implementation.generate_email_verify_token_post(
api_options, session, user_context
session, api_options, user_context
)
return send_200_response(result.to_json(), api_options.response)
19 changes: 4 additions & 15 deletions supertokens_python/recipe/emailverification/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CreateEmailVerificationTokenEmailAlreadyVerifiedError,
UnverifyEmailOkResult,
CreateEmailVerificationTokenOkResult,
RevokeEmailVerificationTokensOkResult,
)
from supertokens_python.recipe.emailverification.types import EmailTemplateVars
from supertokens_python.recipe.emailverification.recipe import EmailVerificationRecipe
Expand Down Expand Up @@ -81,11 +82,11 @@ async def is_email_verified(
)


async def revoke_email_verification_token(
async def revoke_email_verification_tokens(
user_id: str,
email: Optional[str] = None,
user_context: Optional[Dict[str, Any]] = None,
):
) -> RevokeEmailVerificationTokensOkResult:
if user_context is None:
user_context = {}

Expand All @@ -95,9 +96,7 @@ async def revoke_email_verification_token(
if isinstance(email_info, GetEmailForUserIdOkResult):
email = email_info.email
elif isinstance(email_info, EmailDoesNotExistError):
# Here we are returning OK since that's how it used to work, but a later call
# to is_verified will still return true
return CreateEmailVerificationTokenEmailAlreadyVerifiedError()
return RevokeEmailVerificationTokensOkResult()
else:
raise Exception("Unknown User ID provided without email")

Expand Down Expand Up @@ -131,16 +130,6 @@ async def unverify_email(
)


async def revoke_email_verification_tokens(
user_id: str, email: str, user_context: Union[None, Dict[str, Any]] = None
):
if user_context is None:
user_context = {}
return await EmailVerificationRecipe.get_instance().recipe_implementation.revoke_email_verification_tokens(
user_id, email, user_context
)


async def send_email(
input_: EmailTemplateVars, user_context: Union[None, Dict[str, Any]] = None
):
Expand Down
82 changes: 0 additions & 82 deletions supertokens_python/recipe/emailverification/ev_claim.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
pass
6 changes: 3 additions & 3 deletions supertokens_python/recipe/emailverification/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def __init__(self):
async def email_verify_post(
self,
token: str,
api_options: APIOptions,
session: Optional[SessionContainer],
api_options: APIOptions,
user_context: Dict[str, Any],
) -> Union[
EmailVerifyPostOkResult, EmailVerifyPostInvalidTokenError, GeneralErrorResponse
Expand All @@ -178,17 +178,17 @@ async def email_verify_post(
@abstractmethod
async def is_email_verified_get(
self,
session: SessionContainer,
api_options: APIOptions,
session: Optional[SessionContainer],
user_context: Dict[str, Any],
) -> Union[IsEmailVerifiedGetOkResult, GeneralErrorResponse]:
pass

@abstractmethod
async def generate_email_verify_token_post(
self,
api_options: APIOptions,
session: SessionContainer,
api_options: APIOptions,
user_context: Dict[str, Any],
) -> Union[
GenerateEmailVerifyTokenPostOkResult,
Expand Down
Loading