🎨 Format files with pre-commit and Ruff (#611)
This commit is contained in:

committed by
GitHub

parent
2802a4df9e
commit
0cc802eec8
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any
|
||||
|
||||
import emails
|
||||
from emails.template import JinjaTemplate
|
||||
@@ -14,8 +14,9 @@ def send_email(
|
||||
email_to: str,
|
||||
subject_template: str = "",
|
||||
html_template: str = "",
|
||||
environment: Dict[str, Any] = {},
|
||||
environment: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
current_environment = environment or {}
|
||||
assert settings.EMAILS_ENABLED, "no provided configuration for email variables"
|
||||
message = emails.Message(
|
||||
subject=JinjaTemplate(subject_template),
|
||||
@@ -29,7 +30,7 @@ def send_email(
|
||||
smtp_options["user"] = settings.SMTP_USER
|
||||
if settings.SMTP_PASSWORD:
|
||||
smtp_options["password"] = settings.SMTP_PASSWORD
|
||||
response = message.send(to=email_to, render=environment, smtp=smtp_options)
|
||||
response = message.send(to=email_to, render=current_environment, smtp=smtp_options)
|
||||
logging.info(f"send email result: {response}")
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ def send_test_email(email_to: str) -> None:
|
||||
email_to=email_to,
|
||||
subject_template=subject,
|
||||
html_template=template_str,
|
||||
environment={"project_name": settings.PROJECT_NAME, "email": email_to},
|
||||
current_environment={"project_name": settings.PROJECT_NAME, "email": email_to},
|
||||
)
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ def send_reset_password_email(email_to: str, email: str, token: str) -> None:
|
||||
email_to=email_to,
|
||||
subject_template=subject,
|
||||
html_template=template_str,
|
||||
environment={
|
||||
current_environment={
|
||||
"project_name": settings.PROJECT_NAME,
|
||||
"username": email,
|
||||
"email": email_to,
|
||||
@@ -77,7 +78,7 @@ def send_new_account_email(email_to: str, username: str, password: str) -> None:
|
||||
email_to=email_to,
|
||||
subject_template=subject,
|
||||
html_template=template_str,
|
||||
environment={
|
||||
current_environment={
|
||||
"project_name": settings.PROJECT_NAME,
|
||||
"username": username,
|
||||
"password": password,
|
||||
@@ -93,12 +94,14 @@ def generate_password_reset_token(email: str) -> str:
|
||||
expires = now + delta
|
||||
exp = expires.timestamp()
|
||||
encoded_jwt = jwt.encode(
|
||||
{"exp": exp, "nbf": now, "sub": email}, settings.SECRET_KEY, algorithm="HS256",
|
||||
{"exp": exp, "nbf": now, "sub": email},
|
||||
settings.SECRET_KEY,
|
||||
algorithm="HS256",
|
||||
)
|
||||
return encoded_jwt
|
||||
|
||||
|
||||
def verify_password_reset_token(token: str) -> Optional[str]:
|
||||
def verify_password_reset_token(token: str) -> str | None:
|
||||
try:
|
||||
decoded_token = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"])
|
||||
return decoded_token["email"]
|
||||
|
Reference in New Issue
Block a user