Skip to content

Commit

Permalink
fix: added dedent to strings in emails
Browse files Browse the repository at this point in the history
Signed-off-by: Trey <[email protected]>
  • Loading branch information
TreyWW committed Sep 15, 2024
1 parent c0f3514 commit 2775266
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
8 changes: 6 additions & 2 deletions backend/api/teams/invites.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from textwrap import dedent

from backend.decorators import *
from backend.models import Notification, Organization, TeamInvitation, User
from backend.types.emails import SingleEmailInput
Expand Down Expand Up @@ -96,7 +98,8 @@ def return_error_notif(request: HtmxHttpRequest, message: str, autohide=None):
SingleEmailInput(
destination=user.email,
subject="New Organization Invite",
content=f"""
content=dedent(
f"""
Hi {user.first_name or "User"},
{request.user.first_name or f"User {request.user.email}"} has invited you to join the organization \"{team.name}\" (#{team.id})
Expand All @@ -107,7 +110,8 @@ def return_error_notif(request: HtmxHttpRequest, message: str, autohide=None):
Didn't give permission to be added to this organization? You can safely ignore the email, no actions can be done on
behalf of you without your action.
""",
"""
),
)
)

Expand Down
8 changes: 6 additions & 2 deletions backend/service/teams/create_user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from textwrap import dedent

from django.urls import reverse
from django.utils.crypto import get_random_string

Expand Down Expand Up @@ -35,7 +37,8 @@ def create_user_service(
SingleEmailInput(
destination=email,
subject="MyFinances | You have been invited to join an organization",
content=f"""
content=dedent(
f"""
Hi {user.first_name or "User"},
You have been invited by {request.user.email} to join the organization {team.name}.
Expand All @@ -53,7 +56,8 @@ def create_user_service(
Didn't give permission to be added to this organization? You can safely ignore the email, no actions can be done on
behalf of you without your permission.
""",
"""
),
)
)

Expand Down
8 changes: 6 additions & 2 deletions backend/views/core/auth/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from textwrap import dedent

import django_ratelimit
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.hashers import check_password
Expand Down Expand Up @@ -144,14 +146,16 @@ def send_magic_link_email(self, request: HttpRequest, user: User, uuid: str, pla
email: SingleEmailInput = SingleEmailInput(
destination=user.email,
subject="Login Request",
content=f"""
content=dedent(
f"""
Hi {user.first_name if user.first_name else "User"},
A login request was made on your MyFinances account. If this was not you, please ignore
this email.
If you would like to login, please use the following link: \n {magic_link_url}
""",
"""
),
)
send_email(email)

Expand Down
29 changes: 18 additions & 11 deletions backend/views/core/auth/verify.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from textwrap import dedent

from django.contrib import messages
from django.contrib.auth.hashers import check_password
from django.shortcuts import redirect
Expand All @@ -7,6 +9,7 @@
from django_ratelimit.decorators import ratelimit

from backend.models import VerificationCodes, User, TracebackError
from backend.types.emails import SingleEmailInput
from settings import settings
from settings.helpers import send_email, ARE_EMAILS_ENABLED

Expand Down Expand Up @@ -72,17 +75,21 @@ def resend_verification_code(request):
magic_link_url = settings.SITE_URL + reverse("auth:login create_account verify", kwargs={"uuid": magic_link.uuid, "token": token_plain})

send_email(
destination=email,
subject="Verify your email",
message=f"""
Hi {user.first_name if user.first_name else "User"},
Verification for your email has been requested to link this email to your MyFinances account.
If this wasn't you, you can simply ignore this email.
If it was you, you can complete the verification by clicking the link below.
Verify Link: {magic_link_url}
""",
SingleEmailInput(
destination=email,
subject="Verify your email",
content=dedent(
f"""
Hi {user.first_name if user.first_name else "User"},
Verification for your email has been requested to link this email to your MyFinances account.
If this wasn't you, you can simply ignore this email.
If it was you, you can complete the verification by clicking the link below.
Verify Link: {magic_link_url}
"""
),
)
)

messages.success(request, "Verification email sent, check your inbox or spam!")
Expand Down

0 comments on commit 2775266

Please sign in to comment.