forked from sh-edraft.de/sh_discord_bot
Fixed multiple send mails error #70
This commit is contained in:
parent
ecd648a9b2
commit
a691808068
@ -11,12 +11,11 @@ from flask import Flask
|
|||||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||||
from bot_api.api import Api
|
from bot_api.api import Api
|
||||||
from bot_api.api_thread import ApiThread
|
from bot_api.api_thread import ApiThread
|
||||||
|
from bot_api.controller.auth_controller import AuthController
|
||||||
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
||||||
from bot_api.controller.discord.server_controller import ServerController
|
from bot_api.controller.discord.server_controller import ServerController
|
||||||
from bot_api.controller.gui_controller import GuiController
|
from bot_api.controller.gui_controller import GuiController
|
||||||
from bot_api.controller.auth_controller import AuthController
|
|
||||||
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
||||||
from bot_api.mail.mail_thread import MailThread
|
|
||||||
from bot_api.service.auth_service import AuthService
|
from bot_api.service.auth_service import AuthService
|
||||||
from bot_api.service.discord_service import DiscordService
|
from bot_api.service.discord_service import DiscordService
|
||||||
from bot_core.abc.module_abc import ModuleABC
|
from bot_core.abc.module_abc import ModuleABC
|
||||||
@ -38,7 +37,6 @@ class ApiModule(ModuleABC):
|
|||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||||
services.add_singleton(EMailClientABC, EMailClient)
|
services.add_singleton(EMailClientABC, EMailClient)
|
||||||
services.add_singleton(MailThread)
|
|
||||||
|
|
||||||
services.add_singleton(ApiThread)
|
services.add_singleton(ApiThread)
|
||||||
services.add_singleton(Flask, Api)
|
services.add_singleton(Flask, Api)
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
bot Keksdose bot
|
|
||||||
~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Discord bot for the Keksdose discord Server
|
|
||||||
|
|
||||||
:copyright: (c) 2022 sh-edraft.de
|
|
||||||
:license: MIT, see LICENSE for more details.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
__title__ = 'bot_api.mail'
|
|
||||||
__author__ = 'Sven Heidemann'
|
|
||||||
__license__ = 'MIT'
|
|
||||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
|
||||||
__version__ = '0.3.dev70'
|
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
|
|
||||||
# imports
|
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
|
||||||
version_info = VersionInfo(major='0', minor='3', micro='dev70')
|
|
@ -1,23 +0,0 @@
|
|||||||
import threading
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from cpl_core.mailing import EMailClientABC, EMail
|
|
||||||
|
|
||||||
|
|
||||||
class MailThread(threading.Thread):
|
|
||||||
|
|
||||||
def __init__(self, mailer: EMailClientABC):
|
|
||||||
threading.Thread.__init__(self, daemon=True)
|
|
||||||
|
|
||||||
self._mailer = mailer
|
|
||||||
self._mail: Optional[EMail] = None
|
|
||||||
|
|
||||||
def send_mail(self, mail: EMail):
|
|
||||||
self._mail = mail
|
|
||||||
self.start()
|
|
||||||
|
|
||||||
def run(self) -> None:
|
|
||||||
if self._mailer is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
self._mailer.send_mail(self._mail)
|
|
@ -3,12 +3,13 @@ import re
|
|||||||
import textwrap
|
import textwrap
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from threading import Thread
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_core.environment import ApplicationEnvironmentABC
|
from cpl_core.environment import ApplicationEnvironmentABC
|
||||||
from cpl_core.mailing import EMail
|
from cpl_core.mailing import EMail, EMailClientABC
|
||||||
from cpl_core.utils import CredentialManager
|
from cpl_core.utils import CredentialManager
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
@ -22,7 +23,6 @@ from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
|||||||
from bot_api.exception.service_exception import ServiceException
|
from bot_api.exception.service_exception import ServiceException
|
||||||
from bot_api.filter.auth_user_select_criteria import AuthUserSelectCriteria
|
from bot_api.filter.auth_user_select_criteria import AuthUserSelectCriteria
|
||||||
from bot_api.logging.api_logger import ApiLogger
|
from bot_api.logging.api_logger import ApiLogger
|
||||||
from bot_api.mail.mail_thread import MailThread
|
|
||||||
from bot_api.model.auth_user_dto import AuthUserDTO
|
from bot_api.model.auth_user_dto import AuthUserDTO
|
||||||
from bot_api.model.auth_user_filtered_result_dto import AuthUserFilteredResultDTO
|
from bot_api.model.auth_user_filtered_result_dto import AuthUserFilteredResultDTO
|
||||||
from bot_api.model.email_string_dto import EMailStringDTO
|
from bot_api.model.email_string_dto import EMailStringDTO
|
||||||
@ -37,7 +37,6 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC
|
|||||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||||
from bot_data.model.auth_user import AuthUser
|
from bot_data.model.auth_user import AuthUser
|
||||||
from bot_data.model.auth_user_users_relation import AuthUserUsersRelation
|
from bot_data.model.auth_user_users_relation import AuthUserUsersRelation
|
||||||
from bot_data.model.user import User
|
|
||||||
|
|
||||||
_email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
|
_email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
|
||||||
|
|
||||||
@ -53,7 +52,8 @@ class AuthService(AuthServiceABC):
|
|||||||
auth_users: AuthUserRepositoryABC,
|
auth_users: AuthUserRepositoryABC,
|
||||||
users: UserRepositoryABC,
|
users: UserRepositoryABC,
|
||||||
servers: ServerRepositoryABC,
|
servers: ServerRepositoryABC,
|
||||||
mailer: MailThread,
|
# mailer: MailThread,
|
||||||
|
mailer: EMailClientABC,
|
||||||
t: TranslatePipe,
|
t: TranslatePipe,
|
||||||
auth_settings: AuthenticationSettings,
|
auth_settings: AuthenticationSettings,
|
||||||
frontend_settings: FrontendSettings,
|
frontend_settings: FrontendSettings,
|
||||||
@ -152,6 +152,7 @@ class AuthService(AuthServiceABC):
|
|||||||
if not url.endswith('/'):
|
if not url.endswith('/'):
|
||||||
url = f'{url}/'
|
url = f'{url}/'
|
||||||
|
|
||||||
|
self._mailer.connect()
|
||||||
mail = EMail()
|
mail = EMail()
|
||||||
mail.add_header('Mime-Version: 1.0')
|
mail.add_header('Mime-Version: 1.0')
|
||||||
mail.add_header('Content-Type: text/plain; charset=utf-8')
|
mail.add_header('Content-Type: text/plain; charset=utf-8')
|
||||||
@ -161,7 +162,9 @@ class AuthService(AuthServiceABC):
|
|||||||
mail.body = textwrap.dedent(f"""{message}
|
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)}
|
{self._t.transform('api.mail.automatic_mail').format(self._environment.application_name, self._environment.environment_name, self._environment.host_name)}
|
||||||
""")
|
""")
|
||||||
self._mailer.send_mail(mail)
|
|
||||||
|
thr = Thread(target=self._mailer.send_mail, args=[mail])
|
||||||
|
thr.start()
|
||||||
|
|
||||||
def _send_confirmation_id_to_user(self, user: AuthUser):
|
def _send_confirmation_id_to_user(self, user: AuthUser):
|
||||||
url = self._frontend_settings.url
|
url = self._frontend_settings.url
|
||||||
|
@ -1,54 +1,54 @@
|
|||||||
{
|
{
|
||||||
"name": "kdb-web",
|
"name": "kdb-web",
|
||||||
"version": "0.3.dev70",
|
"version": "0.3.dev70",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts",
|
"update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts",
|
||||||
"prestart": "npm run update-version",
|
"prestart": "npm run update-version",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
"prebuild": "npm run update-version",
|
"prebuild": "npm run update-version",
|
||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"watch": "ng build --watch --configuration development",
|
"watch": "ng build --watch --configuration development",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"docker-build": "export VERSION=$npm_package_version; ng build; docker build -t kdb-web/kdb-web:$VERSION .",
|
"docker-build": "export VERSION=$npm_package_version; ng build; docker build -t kdb-web/kdb-web:$VERSION .",
|
||||||
"docker-build-dev": "export VERSION=$npm_package_version; ng build --configuration development; docker build -t kdb-web/kdb-web:$VERSION .",
|
"docker-build-dev": "export VERSION=$npm_package_version; ng build --configuration development; docker build -t kdb-web/kdb-web:$VERSION .",
|
||||||
"docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t kdb-web/kdb-web:$VERSION ."
|
"docker-build-stage": "export VERSION=$npm_package_version; ng build --configuration staging; docker build -t kdb-web/kdb-web:$VERSION ."
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^14.0.0",
|
"@angular/animations": "^14.0.0",
|
||||||
"@angular/common": "^14.0.0",
|
"@angular/common": "^14.0.0",
|
||||||
"@angular/compiler": "^14.0.0",
|
"@angular/compiler": "^14.0.0",
|
||||||
"@angular/core": "^14.0.0",
|
"@angular/core": "^14.0.0",
|
||||||
"@angular/forms": "^14.0.0",
|
"@angular/forms": "^14.0.0",
|
||||||
"@angular/platform-browser": "^14.0.0",
|
"@angular/platform-browser": "^14.0.0",
|
||||||
"@angular/platform-browser-dynamic": "^14.0.0",
|
"@angular/platform-browser-dynamic": "^14.0.0",
|
||||||
"@angular/router": "^14.0.0",
|
"@angular/router": "^14.0.0",
|
||||||
"@auth0/angular-jwt": "^5.1.0",
|
"@auth0/angular-jwt": "^5.1.0",
|
||||||
"@microsoft/signalr": "^6.0.9",
|
"@microsoft/signalr": "^6.0.9",
|
||||||
"@ngx-translate/core": "^14.0.0",
|
"@ngx-translate/core": "^14.0.0",
|
||||||
"@ngx-translate/http-loader": "^7.0.0",
|
"@ngx-translate/http-loader": "^7.0.0",
|
||||||
"@types/socket.io-client": "^3.0.0",
|
"@types/socket.io-client": "^3.0.0",
|
||||||
"primeicons": "^6.0.1",
|
"primeicons": "^6.0.1",
|
||||||
"primeng": "^14.1.2",
|
"primeng": "^14.1.2",
|
||||||
"rxjs": "~7.5.0",
|
"rxjs": "~7.5.0",
|
||||||
"socket.io-client": "^4.5.3",
|
"socket.io-client": "^4.5.3",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"zone.js": "~0.11.4"
|
"zone.js": "~0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "^14.0.0",
|
"@angular-devkit/build-angular": "^14.0.0",
|
||||||
"@angular/cli": "~14.0.0",
|
"@angular/cli": "~14.0.0",
|
||||||
"@angular/compiler-cli": "^14.0.0",
|
"@angular/compiler-cli": "^14.0.0",
|
||||||
"@types/jasmine": "~4.0.0",
|
"@types/jasmine": "~4.0.0",
|
||||||
"@types/node": "^18.8.3",
|
"@types/node": "^18.8.3",
|
||||||
"jasmine-core": "~4.1.0",
|
"jasmine-core": "~4.1.0",
|
||||||
"karma": "~6.3.0",
|
"karma": "~6.3.0",
|
||||||
"karma-chrome-launcher": "~3.1.0",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
"karma-coverage": "~2.2.0",
|
"karma-coverage": "~2.2.0",
|
||||||
"karma-jasmine": "~5.0.0",
|
"karma-jasmine": "~5.0.0",
|
||||||
"karma-jasmine-html-reporter": "~1.7.0",
|
"karma-jasmine-html-reporter": "~1.7.0",
|
||||||
"ts-node": "~8.3.0",
|
"ts-node": "~8.3.0",
|
||||||
"typescript": "~4.7.2"
|
"typescript": "~4.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiURL: "https://kdb_web_prod_1",
|
apiURL: "http://localhost:5000",
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user