Resend confirmation mail
Some checks failed
Deploy staging on push / pre-build (push) Successful in 1s
Deploy staging on push / build-bot (push) Failing after 22s
Deploy staging on push / build-web (push) Failing after 21s
Deploy staging on push / deploy (push) Has been skipped

This commit is contained in:
2024-01-26 15:32:01 +01:00
parent a24fefd3e2
commit 60d81ce18b
9 changed files with 77 additions and 43 deletions

View File

@@ -2,22 +2,22 @@
"api": {
"api": {
"test_mail": {
"message": "Dies ist eine Test-Mail vom Kruemelmonster Web Interface\r\nGesendet von {}-{}",
"message": "Dies ist eine Test-Mail vom Krümelmonster Web Interface\r\nGesendet von {}-{}",
"subject": "Krümelmonster Web Interface Test-Mail"
}
},
"auth": {
"confirmation": {
"message": "Öffne den Link, um die E-Mail zu bestätigen:\n{}auth/register/{}",
"message": "Öffne den Link, um die E-Mail zu bestätigen:\r\n{}auth/register/{}",
"subject": "E-Mail für {} {} bestätigen"
},
"forgot_password": {
"message": "Öffne den Link, um das Passwort zu ändern:\n{}auth/forgot-password/{}",
"message": "Öffne den Link, um das Passwort zu ändern:\r\n{}auth/forgot-password/{}",
"subject": "Passwort für {} {} zurücksetzen"
}
},
"mail": {
"automatic_mail": "\n\nDies ist eine automatische E-Mail.\nGesendet von {}-{}@{}"
"automatic_mail": "\r\n\r\nDies ist eine automatische E-Mail.\r\nGesendet von {}-{}@{}"
}
},
"common": {

View File

@@ -114,3 +114,7 @@ class AuthServiceABC(ABC):
@abstractmethod
async def reset_password_async(self, rp_dto: ResetPasswordDTO):
pass
@abstractmethod
async def resend_confirmation_email_by_mail(self, mail: str):
pass

View File

@@ -84,6 +84,11 @@ class AuthController:
self._auth_service.add_auth_user(dto)
return "", 200
@Route.post(f"{BasePath}/resend-confirmation-email-by-mail/<mail>")
async def resend_confirmation_email_by_user_id(self, mail: str):
await self._auth_service.resend_confirmation_email_by_mail(mail)
return "", 200
@Route.post(f"{BasePath}/register-by-id/<id>")
async def register_id(self, id: str):
result = await self._auth_service.confirm_email_async(id)

View File

@@ -16,6 +16,7 @@ from bot_api.api import Api
from bot_api.configuration.discord_authentication_settings import (
DiscordAuthenticationSettings,
)
from bot_api.exception.service_exception import ServiceException
from bot_api.logging.api_logger import ApiLogger
from bot_api.model.auth_user_dto import AuthUserDTO
from bot_api.route.route import Route
@@ -90,5 +91,10 @@ class AuthDiscordController:
AuthRoleEnum.normal,
)
result = await self._auth_service.login_discord_async(dto, response["id"])
return jsonify(result.to_dict())
try:
result = await self._auth_service.login_discord_async(dto, response["id"])
return jsonify(result.to_dict())
except ServiceException as e:
r = jsonify({"email": dto.email})
r.status_code = 403
return r

View File

@@ -1,6 +1,5 @@
import hashlib
import re
import textwrap
import uuid
from datetime import datetime, timedelta, timezone
from threading import Thread
@@ -172,11 +171,7 @@ class AuthService(AuthServiceABC):
mail.add_header("Content-Transfer-Encoding: quoted-printable")
mail.add_receiver(str(email))
mail.subject = subject
mail.body = textwrap.dedent(
f"""{message}
{self._t.transform('api.mail.automatic_mail').format(self._environment.application_name, self._environment.environment_name, self._environment.host_name)}
"""
)
mail.body = f"{message}\r\n{self._t.transform('api.mail.automatic_mail').format(self._environment.application_name, self._environment.environment_name, self._environment.host_name)}"
thr = Thread(target=self._mailer.send_mail, args=[mail])
thr.start()
@@ -599,3 +594,12 @@ class AuthService(AuthServiceABC):
user.forgot_password_id = None
self._auth_users.update_auth_user(user)
self._db.save_changes()
async def resend_confirmation_email_by_mail(self, mail: str):
user = self._auth_users.find_auth_user_by_email(mail)
if user is None:
raise ServiceException(ServiceErrorCode.InvalidUser, f"User not found")
if user.confirmation_id is None:
raise ServiceException(ServiceErrorCode.DataAlreadyExists, f"User already confirmed")
self._send_confirmation_id_to_user(user)