|
13 | 13 | # under the License.
|
14 | 14 | from __future__ import annotations
|
15 | 15 |
|
16 |
| -from typing import TYPE_CHECKING, Any, Dict, Union, Optional |
17 |
| - |
18 |
| -from supertokens_python.logger import log_debug_message |
19 |
| -from supertokens_python.recipe.emailverification import ( |
20 |
| - EmailVerificationRecipe, |
21 |
| - EmailVerificationClaim, |
22 |
| -) |
23 |
| -from supertokens_python.recipe.emailverification.interfaces import ( |
24 |
| - APIInterface, |
25 |
| - CreateEmailVerificationTokenEmailAlreadyVerifiedError, |
26 |
| - EmailVerifyPostInvalidTokenError, |
27 |
| - EmailVerifyPostOkResult, |
28 |
| - GenerateEmailVerifyTokenPostEmailAlreadyVerifiedError, |
29 |
| - GenerateEmailVerifyTokenPostOkResult, |
30 |
| - IsEmailVerifiedGetOkResult, |
31 |
| - VerifyEmailUsingTokenOkResult, |
32 |
| - EmailDoesnotExistError, |
33 |
| - GetEmailForUserIdOkResult, |
34 |
| -) |
35 |
| -from supertokens_python.recipe.session.interfaces import SessionContainer |
| 16 | +from typing import TYPE_CHECKING |
36 | 17 |
|
37 | 18 | if TYPE_CHECKING:
|
38 |
| - from supertokens_python.recipe.emailverification.interfaces import APIOptions |
39 |
| - |
40 |
| -from supertokens_python.recipe.emailverification.types import ( |
41 |
| - VerificationEmailTemplateVarsUser, |
42 |
| - VerificationEmailTemplateVars, |
43 |
| -) |
44 |
| - |
45 |
| - |
46 |
| -class APIImplementation(APIInterface): |
47 |
| - async def email_verify_post( |
48 |
| - self, |
49 |
| - token: str, |
50 |
| - api_options: APIOptions, |
51 |
| - user_context: Dict[str, Any], |
52 |
| - session: Optional[SessionContainer] = None, |
53 |
| - ) -> Union[EmailVerifyPostOkResult, EmailVerifyPostInvalidTokenError]: |
54 |
| - response = await api_options.recipe_implementation.verify_email_using_token( |
55 |
| - token, user_context |
56 |
| - ) |
57 |
| - if isinstance(response, VerifyEmailUsingTokenOkResult): |
58 |
| - if session is not None: |
59 |
| - await session.fetch_and_set_claim(EmailVerificationClaim, user_context) |
60 |
| - |
61 |
| - return EmailVerifyPostOkResult(response.user) |
62 |
| - return EmailVerifyPostInvalidTokenError() |
63 |
| - |
64 |
| - async def is_email_verified_get( |
65 |
| - self, |
66 |
| - api_options: APIOptions, |
67 |
| - user_context: Dict[str, Any], |
68 |
| - session: Optional[SessionContainer] = None, |
69 |
| - ) -> IsEmailVerifiedGetOkResult: |
70 |
| - if session is None: |
71 |
| - raise Exception("Session is undefined. Should not come here.") |
72 |
| - await session.fetch_and_set_claim(EmailVerificationClaim, user_context) |
73 |
| - is_verified = await session.get_claim_value( |
74 |
| - EmailVerificationClaim, user_context |
75 |
| - ) |
76 |
| - # TODO: Type of is_verified should be bool. It's any for now. |
77 |
| - |
78 |
| - if is_verified is None: |
79 |
| - raise Exception( |
80 |
| - "Should never come here: EmailVerificationClaim failed to set value" |
81 |
| - ) |
82 |
| - |
83 |
| - return IsEmailVerifiedGetOkResult(is_verified) |
84 |
| - |
85 |
| - async def generate_email_verify_token_post( |
86 |
| - self, |
87 |
| - api_options: APIOptions, |
88 |
| - user_context: Dict[str, Any], |
89 |
| - session: SessionContainer, |
90 |
| - ) -> Union[ |
91 |
| - GenerateEmailVerifyTokenPostOkResult, |
92 |
| - GenerateEmailVerifyTokenPostEmailAlreadyVerifiedError, |
93 |
| - ]: |
94 |
| - if session is None: |
95 |
| - raise Exception("Session is undefined. Should not come here.") |
96 |
| - |
97 |
| - user_id = session.get_user_id(user_context) |
98 |
| - email_info = await EmailVerificationRecipe.get_instance().get_email_for_user_id( |
99 |
| - user_id, user_context |
100 |
| - ) |
101 |
| - |
102 |
| - if isinstance(email_info, EmailDoesnotExistError): |
103 |
| - log_debug_message( |
104 |
| - "Email verification email not sent to user %s because it doesn't have an email address.", |
105 |
| - user_id, |
106 |
| - ) |
107 |
| - return GenerateEmailVerifyTokenPostEmailAlreadyVerifiedError() |
108 |
| - if isinstance(email_info, GetEmailForUserIdOkResult): |
109 |
| - response = ( |
110 |
| - await api_options.recipe_implementation.create_email_verification_token( |
111 |
| - user_id, |
112 |
| - email_info.email, |
113 |
| - user_context, |
114 |
| - ) |
115 |
| - ) |
116 |
| - |
117 |
| - if isinstance( |
118 |
| - response, CreateEmailVerificationTokenEmailAlreadyVerifiedError |
119 |
| - ): |
120 |
| - log_debug_message( |
121 |
| - "Email verification email not sent to %s because it is already verified.", |
122 |
| - email_info.email, |
123 |
| - ) |
124 |
| - return GenerateEmailVerifyTokenPostEmailAlreadyVerifiedError() |
125 |
| - |
126 |
| - email_verify_link = ( |
127 |
| - api_options.app_info.website_domain.get_as_string_dangerous() |
128 |
| - + api_options.app_info.website_base_path.get_as_string_dangerous() |
129 |
| - + "/verify-email/" |
130 |
| - + "?token=" |
131 |
| - + response.token |
132 |
| - + "&rid=" |
133 |
| - + api_options.recipe_id |
134 |
| - ) |
135 |
| - |
136 |
| - log_debug_message("Sending email verification email to %s", email_info) |
137 |
| - email_verification_email_delivery_input = VerificationEmailTemplateVars( |
138 |
| - user=VerificationEmailTemplateVarsUser(user_id, email_info.email), |
139 |
| - email_verify_link=email_verify_link, |
140 |
| - user_context=user_context, |
141 |
| - ) |
142 |
| - await api_options.email_delivery.ingredient_interface_impl.send_email( |
143 |
| - email_verification_email_delivery_input, user_context |
144 |
| - ) |
145 |
| - return GenerateEmailVerifyTokenPostOkResult() |
146 |
| - |
147 |
| - raise Exception( |
148 |
| - "Should never come here: UNKNOWN_USER_ID or invalid result from get_email_for_user_id" |
149 |
| - ) |
| 19 | + pass |
0 commit comments