Skip to content

Commit

Permalink
feat: Update password recovery service to use language parameter for …
Browse files Browse the repository at this point in the history
…localized email subject
  • Loading branch information
Ramir Mesquita committed Nov 6, 2024
1 parent 75d0489 commit 6e45bee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/apps/users/api/password.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
from typing import Annotated

from apps.shared.enums import Language
from fastapi import Body, Depends, Query, Request
from pydantic import Required
from starlette import status
Expand Down Expand Up @@ -72,8 +73,10 @@ async def password_recovery(
async with atomic(session):
try:
content_source = await get_mindlogger_content_source(request)
content_language = request.headers.get("content-language", "en")
await PasswordRecoveryService(session).send_password_recovery(schema, content_source, content_language)
content_language: Language = request.headers.get("content-language", "en")
await PasswordRecoveryService(session).send_password_recovery(
schema, content_source, language=content_language
)
except UserNotFound:
pass # mute error in terms of user enumeration vulnerability

Expand Down
8 changes: 6 additions & 2 deletions src/apps/users/services/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def send_password_recovery(
self,
schema: PasswordRecoveryRequest,
content_source: MindloggerContentSource,
content_language: Language,
language: Language,
) -> PublicUser:
user: User = await UsersCRUD(self.session).get_by_email(schema.email)

Expand Down Expand Up @@ -93,9 +93,13 @@ async def send_password_recovery(
message = MessageSchema(
recipients=[user.email_encrypted],
subject="Password reset",
subject=service.get_localized_string(
key="password_reset_subject",
language=language,
),
body=service.get_localized_html_template(
template_name="reset_password",
language=content_language,
language=language,
email=user.email_encrypted,
expiration_minutes=exp,
url=url,
Expand Down

0 comments on commit 6e45bee

Please sign in to comment.