From ecd648a9b21e8b9caf642441a1149ff2a0cbcc0a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 23 Oct 2022 14:24:23 +0200 Subject: [PATCH] Fixed confirmation id None on discord registration #70 --- kdb-bot/src/bot_api/service/auth_service.py | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/kdb-bot/src/bot_api/service/auth_service.py b/kdb-bot/src/bot_api/service/auth_service.py index 5fd1ca32..f6556c9b 100644 --- a/kdb-bot/src/bot_api/service/auth_service.py +++ b/kdb-bot/src/bot_api/service/auth_service.py @@ -171,7 +171,7 @@ class AuthService(AuthServiceABC): self._send_link_mail( user.email, self._t.transform('api.auth.confirmation.subject').format(user.first_name, user.last_name), - self._t.transform('api.auth.confirmation.message').format(url, user.forgot_password_id) + self._t.transform('api.auth.confirmation.message').format(url, user.confirmation_id) ) def _send_forgot_password_id_to_user(self, user: AuthUser): @@ -232,7 +232,7 @@ class AuthService(AuthServiceABC): self._db.save_changes() self._logger.info(__name__, f'Added auth user with E-Mail: {user_dto.email}') except Exception as e: - self._logger.error(__name__, f'Cannot add user with E-Mal {user_dto.email}', e) + self._logger.error(__name__, f'Cannot add user with E-Mail {user_dto.email}', e) raise ServiceException(ServiceErrorCode.UnableToAdd, "Invalid E-Mail") async def add_auth_user_by_oauth_async(self, dto: OAuthDTO): @@ -244,12 +244,20 @@ class AuthService(AuthServiceABC): if db_user.oauth_id != dto.oauth_id: raise ServiceException(ServiceErrorCode.InvalidUser, 'Wrong OAuthId') - db_user.first_name = dto.user.first_name - db_user.last_name = dto.user.last_name - db_user.password_salt = uuid.uuid4() - db_user.password = self._hash_sha256(dto.user.password, db_user.password_salt) - db_user.oauth_id = None - self._auth_users.update_auth_user(db_user) + try: + db_user.first_name = dto.user.first_name + db_user.last_name = dto.user.last_name + db_user.password_salt = uuid.uuid4() + db_user.password = self._hash_sha256(dto.user.password, db_user.password_salt) + db_user.oauth_id = None + db_user.confirmation_id = uuid.uuid4() + self._send_confirmation_id_to_user(db_user) + self._auth_users.update_auth_user(db_user) + self._logger.info(__name__, f'Added auth user with E-Mail: {dto.user.email}') + except Exception as e: + self._logger.error(__name__, f'Cannot add user with E-Mail {dto.user.email}', e) + raise ServiceException(ServiceErrorCode.UnableToAdd, "Invalid E-Mail") + self._db.save_changes() async def add_auth_user_by_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> OAuthDTO: