|
9 | 9 | from jinja2 import Template |
10 | 10 | from jwt.exceptions import InvalidTokenError |
11 | 11 |
|
| 12 | +from app.core import security |
12 | 13 | from app.core.config import settings |
13 | 14 |
|
| 15 | +logging.basicConfig(level=logging.INFO) |
| 16 | +logger = logging.getLogger(__name__) |
| 17 | + |
14 | 18 |
|
15 | 19 | @dataclass |
16 | 20 | class EmailData: |
@@ -48,7 +52,7 @@ def send_email( |
48 | 52 | if settings.SMTP_PASSWORD: |
49 | 53 | smtp_options["password"] = settings.SMTP_PASSWORD |
50 | 54 | response = message.send(to=email_to, smtp=smtp_options) |
51 | | - logging.info(f"send email result: {response}") |
| 55 | + logger.info(f"send email result: {response}") |
52 | 56 |
|
53 | 57 |
|
54 | 58 | def generate_test_email(email_to: str) -> EmailData: |
@@ -104,14 +108,16 @@ def generate_password_reset_token(email: str) -> str: |
104 | 108 | encoded_jwt = jwt.encode( |
105 | 109 | {"exp": exp, "nbf": now, "sub": email}, |
106 | 110 | settings.SECRET_KEY, |
107 | | - algorithm="HS256", |
| 111 | + algorithm=security.ALGORITHM, |
108 | 112 | ) |
109 | 113 | return encoded_jwt |
110 | 114 |
|
111 | 115 |
|
112 | 116 | def verify_password_reset_token(token: str) -> str | None: |
113 | 117 | try: |
114 | | - decoded_token = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"]) |
| 118 | + decoded_token = jwt.decode( |
| 119 | + token, settings.SECRET_KEY, algorithms=[security.ALGORITHM] |
| 120 | + ) |
115 | 121 | return str(decoded_token["sub"]) |
116 | 122 | except InvalidTokenError: |
117 | 123 | return None |
0 commit comments