From d0ded956cb3fa5c75eb156a7699470ed1e00e175 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Oct 2022 21:00:13 +0200 Subject: [PATCH] [WIP] Fixed forgot password #70 --- kdb-bot/src/bot/bot.json | 4 +-- kdb-bot/src/bot_api/service/auth_service.py | 27 ++++++++++--------- .../forget-password.component.ts | 1 + .../components/login/login.component.html | 2 +- kdb-web/src/app/services/auth/auth.service.ts | 6 ++--- kdb-web/src/styles.scss | 10 +++---- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index 985c978b2c..f7fdb2cfc5 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core==2022.10.0.post6", + "cpl-core==2022.10.0.post7", "cpl-translation==2022.10.0.post1", "cpl-query==2022.10.0.post2", - "cpl-discord==2022.10.0.post5", + "cpl-discord==2022.10.0.post6", "Flask==2.2.2", "Flask-Classful==0.14.2", "Flask-Cors==3.0.10", diff --git a/kdb-bot/src/bot_api/service/auth_service.py b/kdb-bot/src/bot_api/service/auth_service.py index 3057cd84ea..15fa8138cc 100644 --- a/kdb-bot/src/bot_api/service/auth_service.py +++ b/kdb-bot/src/bot_api/service/auth_service.py @@ -6,6 +6,7 @@ from typing import Optional import jwt from cpl_core.database.context import DatabaseContextABC +from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.mailing import EMailClientABC, EMail from cpl_query.extension import List from cpl_translation import TranslatePipe @@ -35,6 +36,7 @@ class AuthService(AuthServiceABC): def __init__( self, + env: ApplicationEnvironmentABC, logger: ApiLogger, auth_users: AuthUserRepositoryABC, db: DatabaseContextABC, @@ -46,6 +48,7 @@ class AuthService(AuthServiceABC): ): AuthServiceABC.__init__(self) + self._environment = env self._logger = logger self._auth_users = auth_users self._db = db @@ -54,14 +57,6 @@ class AuthService(AuthServiceABC): self._auth_settings = auth_settings self._frontend_settings = frontend_settings - @staticmethod - def _get_mail_to_send() -> EMail: - mail = EMail() - mail.add_header('Mime-Version: 1.0') - mail.add_header('Content-Type: text/plain charset=utf-8') - mail.add_header('Content-Transfer-Encoding: quoted-printable') - return mail - @staticmethod def _hash_sha256(password: str, salt: str) -> str: return hashlib.sha256(f'{password}{salt}'.encode('utf-8')).hexdigest() @@ -141,10 +136,14 @@ class AuthService(AuthServiceABC): if not url.endswith('/'): url = f'{url}/' - mail = self._get_mail_to_send() + mail = EMail() + mail.add_header('Mime-Version: 1.0') + mail.add_header('Content-Type: text/plain charset=utf-8') + mail.add_header('Content-Transfer-Encoding: quoted-printable') mail.add_receiver(user.email) mail.subject = self._t.transform('api.auth.confirmation.subject').format(user.first_name, user.last_name) mail.body = self._t.transform('api.auth.confirmation.message').format(url, user.confirmation_id) + mail.body += f'\n\nDies ist eine automatische E-Mail.\nGesendet von {self._environment.application_name}-{self._environment.environment_name}@{self._environment.host_name}' self._mailer.send_mail(mail) def _send_forgot_password_id_to_user(self, user: AuthUser): @@ -152,10 +151,14 @@ class AuthService(AuthServiceABC): if not url.endswith('/'): url = f'{url}/' - mail = self._get_mail_to_send() + mail = EMail() + mail.add_header('Mime-Version: 1.0') + mail.add_header('Content-Type: text/plain charset=utf-8') + mail.add_header('Content-Transfer-Encoding: quoted-printable') mail.add_receiver(user.email) - mail.subject = self._t.transform('api.auth.forgot_password.subject').format(user.first_name, user.last_name) - mail.body = self._t.transform('api.auth.forgot_password.message').format(url, user.forgot_password_id) + mail.subject = str(self._t.transform('api.auth.forgot_password.subject').format(user.first_name, user.last_name)) + mail.body = str(self._t.transform('api.auth.forgot_password.message').format(url, user.forgot_password_id)) + mail.body += f'\n\nDies ist eine automatische E-Mail.\nGesendet von {self._environment.application_name}-{self._environment.environment_name}@{self._environment.host_name}' self._mailer.send_mail(mail) async def get_all_auth_users_async(self) -> List[AuthUserDTO]: diff --git a/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts b/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts index c49c6be16f..f73bd20e97 100644 --- a/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts +++ b/kdb-web/src/app/modules/auth/components/forget-password/forget-password.component.ts @@ -37,6 +37,7 @@ export class ForgetPasswordComponent implements OnInit { ) { } ngOnInit(): void { + console.log('test'); this.spinnerService.showSpinner(); this.authService.isUserLoggedInAsync().then(result => { if (result) { diff --git a/kdb-web/src/app/modules/auth/components/login/login.component.html b/kdb-web/src/app/modules/auth/components/login/login.component.html index 54789beefb..d6ee032619 100644 --- a/kdb-web/src/app/modules/auth/components/login/login.component.html +++ b/kdb-web/src/app/modules/auth/components/login/login.component.html @@ -2,7 +2,7 @@