Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brulitsan committed Mar 25, 2024
1 parent 3641f3e commit 8ad6f44
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions sapphire/common/broker/models/email.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import uuid

from pydantic import BaseModel
from pydantic import BaseModel, EmailStr

from sapphire.common.utils import empty

Expand All @@ -13,10 +13,10 @@ class EmailType(str, enum.Enum):
PARTICIPANT_DECLINED = "participant_declined"
PARTICIPANT_LEFT = "participant_left"
OWNER_EXCLUDED = "owner_excluded"
CHANGE_PASSWORD = "change_password"
RESET_PASSWORD = "change_password"


class Email(BaseModel):
type: EmailType
to: list[str]
to: list[EmailStr]
sending_data: dict = {}
3 changes: 2 additions & 1 deletion sapphire/email/sender/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import aiosmtplib
import backoff
from facet import ServiceMixin
from pydantic import EmailStr

from .settings import Settings
from .templates import Template
Expand Down Expand Up @@ -34,7 +35,7 @@ def __init__(
def templates(self) -> dict[str, Template]:
return self._templates

async def send(self, template: Template, data: dict[str, Any], recipients: Iterable[str]):
async def send(self, template: Template, data: dict[str, Any], recipients: Iterable[EmailStr]):
coroutines = []
for recipient in recipients:
message = template.render(recipient=recipient, sender=self._sender, data=data)
Expand Down
4 changes: 2 additions & 2 deletions sapphire/projects/broker/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import uuid

from pydantic import BaseModel
from pydantic import BaseModel, EmailStr

from sapphire.common.broker.models.email import Email, EmailType
from sapphire.common.broker.models.messenger import CreateChat
Expand Down Expand Up @@ -176,7 +176,7 @@ async def _send_notification_to_recipients(self,
await asyncio.gather(*send_tasks)

async def _send_email(
self, recipients: list[str], email_type: EmailType, topic: str = "email"
self, recipients: list[EmailStr], email_type: EmailType, topic: str = "email"
):
await self.send(topic=topic, message=Email(to=recipients, type=email_type))

Expand Down
4 changes: 2 additions & 2 deletions sapphire/users/api/rest/auth/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
router.add_api_route(methods=["POST"], path="/signup", endpoint=handlers.sign_up)
router.add_api_route(methods=["POST"], path="/signin", endpoint=handlers.sign_in)
router.include_router(oauth2.router, prefix="/oauth2")
router.add_api_route(methods=["POST"], path="/change_password", endpoint=handlers.change_password)
router.add_api_route(methods=["POST"], path="/reset_password", endpoint=handlers.reset_password)
router.add_api_route(methods=["POST"], path="/change-password", endpoint=handlers.change_password)
router.add_api_route(methods=["POST"], path="/reset-password", endpoint=handlers.reset_password)
6 changes: 4 additions & 2 deletions sapphire/users/broker/service.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import asyncio

from pydantic import EmailStr

from sapphire.common.broker.models.email import Email, EmailType
from sapphire.common.broker.service import BaseBrokerProducerService

from . import Settings


class Service(BaseBrokerProducerService):
async def send_email_code(self, email: str, code: str, topic: str = "email"):
async def send_email_code(self, email: EmailStr, code: str, topic: str = "email"):
await self.send(
topic=topic,
message=Email(
to=[email],
type=EmailType.CHANGE_PASSWORD,
type=EmailType.RESET_PASSWORD,
sending_data={"code": code}
)
)
Expand Down

0 comments on commit 8ad6f44

Please sign in to comment.