Skip to content

Commit

Permalink
updated linting rules to account for template's lack of docstrings; m…
Browse files Browse the repository at this point in the history
…inor changes to utils module
  • Loading branch information
seekinginfiniteloop committed Jun 19, 2024
1 parent da29228 commit 27e77b4
Show file tree
Hide file tree
Showing 3 changed files with 638 additions and 570 deletions.
14 changes: 6 additions & 8 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any

Expand All @@ -22,16 +22,15 @@ def render_email_template(*, template_name: str, context: dict[str, Any]) -> str
template_str = (
Path(__file__).parent / "email-templates" / "build" / template_name
).read_text()
html_content = Template(template_str).render(context)
return html_content
return Template(template_str).render(context)


def send_email(
*,
email_to: str,
subject: str = "",
html_content: str = "",
) -> None:
) -> None: # sourcery skip: use-fstring-for-concatenation
assert settings.emails_enabled, "no provided configuration for email variables"
message = emails.Message(
subject=subject,
Expand All @@ -48,7 +47,7 @@ def send_email(
if settings.SMTP_PASSWORD:
smtp_options["password"] = settings.SMTP_PASSWORD
response = message.send(to=email_to, smtp=smtp_options)
logging.info(f"send email result: {response}")
logging.info("send email result: %s", response)


def generate_test_email(email_to: str) -> EmailData:
Expand Down Expand Up @@ -98,15 +97,14 @@ def generate_new_account_email(

def generate_password_reset_token(email: str) -> str:
delta = timedelta(hours=settings.EMAIL_RESET_TOKEN_EXPIRE_HOURS)
now = datetime.utcnow()
now = datetime.now(UTC)
expires = now + delta
exp = expires.timestamp()
encoded_jwt = jwt.encode(
return jwt.encode(
{"exp": exp, "nbf": now, "sub": email},
settings.SECRET_KEY,
algorithm="HS256",
)
return encoded_jwt


def verify_password_reset_token(token: str) -> str | None:
Expand Down
Loading

0 comments on commit 27e77b4

Please sign in to comment.