send mail to user when account balances is added to
This commit is contained in:
parent
29caadaca2
commit
af8cf19dc8
@ -46,7 +46,6 @@ class NewTransactionForm(Component):
|
|||||||
label="Betrag",
|
label="Betrag",
|
||||||
suffix_text="€",
|
suffix_text="€",
|
||||||
decimals=2,
|
decimals=2,
|
||||||
thousands_separator=".",
|
|
||||||
margin=1,
|
margin=1,
|
||||||
margin_bottom=0
|
margin_bottom=0
|
||||||
),
|
),
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from rio import Column, Component, event, TextStyle, Text, TextInput, ThemeConte
|
|||||||
PointerEventListener, PointerEvent, Rectangle, CursorStyle, Color, TextInputChangeEvent, Spacer, Row, Switch, \
|
PointerEventListener, PointerEvent, Rectangle, CursorStyle, Color, TextInputChangeEvent, Spacer, Row, Switch, \
|
||||||
SwitchChangeEvent, EventHandler
|
SwitchChangeEvent, EventHandler
|
||||||
|
|
||||||
from src.ezgg_lan_manager import ConfigurationService, UserService, AccountingService, SeatingService
|
from src.ezgg_lan_manager import ConfigurationService, UserService, AccountingService, SeatingService, MailingService
|
||||||
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox
|
from src.ezgg_lan_manager.components.MainViewContentBox import MainViewContentBox
|
||||||
from src.ezgg_lan_manager.components.NewTransactionForm import NewTransactionForm
|
from src.ezgg_lan_manager.components.NewTransactionForm import NewTransactionForm
|
||||||
from src.ezgg_lan_manager.components.UserEditForm import UserEditForm
|
from src.ezgg_lan_manager.components.UserEditForm import UserEditForm
|
||||||
@ -104,11 +104,17 @@ class ManageUsersPage(Component):
|
|||||||
self.accounting_section_result_success = False
|
self.accounting_section_result_success = False
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await self.session[AccountingService].add_balance(
|
new_total_balance = await self.session[AccountingService].add_balance(
|
||||||
transaction.user_id,
|
transaction.user_id,
|
||||||
transaction.value,
|
transaction.value,
|
||||||
transaction.reference
|
transaction.reference
|
||||||
)
|
)
|
||||||
|
user = await self.session[UserService].get_user(transaction.user_id)
|
||||||
|
await self.session[MailingService].send_email(
|
||||||
|
"Dein Guthaben wurde aufgeladen",
|
||||||
|
self.session[MailingService].generate_account_balance_added_mail_body(user, transaction.value, new_total_balance),
|
||||||
|
user.user_mail
|
||||||
|
)
|
||||||
|
|
||||||
self.accounting_section_result_text = f"Guthaben {'entfernt' if transaction.is_debit else 'hinzugefügt'}!"
|
self.accounting_section_result_text = f"Guthaben {'entfernt' if transaction.is_debit else 'hinzugefügt'}!"
|
||||||
self.accounting_section_result_success = True
|
self.accounting_section_result_success = True
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from decimal import Decimal
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
|
|
||||||
import aiosmtplib
|
import aiosmtplib
|
||||||
|
|
||||||
from src.ezgg_lan_manager.services.ConfigurationService import ConfigurationService
|
from src.ezgg_lan_manager.services.ConfigurationService import ConfigurationService
|
||||||
|
from src.ezgg_lan_manager.types.User import User
|
||||||
|
|
||||||
logger = logging.getLogger(__name__.split(".")[-1])
|
logger = logging.getLogger(__name__.split(".")[-1])
|
||||||
|
|
||||||
@ -16,6 +18,9 @@ class MailingService:
|
|||||||
async def send_email(self, subject: str, body: str, receiver: str) -> None:
|
async def send_email(self, subject: str, body: str, receiver: str) -> None:
|
||||||
if self._configuration_service.DEV_MODE_ACTIVE:
|
if self._configuration_service.DEV_MODE_ACTIVE:
|
||||||
logger.info(f"Skipped sending mail to {receiver} because demo mode is active.")
|
logger.info(f"Skipped sending mail to {receiver} because demo mode is active.")
|
||||||
|
logger.info(f"Subject: {subject}")
|
||||||
|
logger.info(f"Receiver: {receiver}")
|
||||||
|
logger.info(f"Body: {body}")
|
||||||
await sleep(1)
|
await sleep(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -35,3 +40,15 @@ class MailingService:
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to send email: {e}")
|
logger.error(f"Failed to send email: {e}")
|
||||||
|
|
||||||
|
def generate_account_balance_added_mail_body(self, user: User, added_balance: Decimal, total_balance: Decimal) -> str:
|
||||||
|
return f"""
|
||||||
|
Hallo {user.user_name},
|
||||||
|
|
||||||
|
deinem Account wurden {added_balance} € hinzugefügt. Dein neues Guthaben beträgt nun {total_balance} €.
|
||||||
|
|
||||||
|
Wenn du zu dieser Aufladung Fragen hast, stehen wir dir in unserem Discord Server oder per Mail an {self._configuration_service.get_lan_info().organizer_mail} zur Verfügung.
|
||||||
|
|
||||||
|
Liebe Grüße
|
||||||
|
Dein {self._configuration_service.get_lan_info().name} Team
|
||||||
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user