Fixed confirmation id None on discord registration #70

This commit is contained in:
Sven Heidemann 2022-10-23 14:24:23 +02:00
parent f891587ce3
commit ecd648a9b2

View File

@ -171,7 +171,7 @@ class AuthService(AuthServiceABC):
self._send_link_mail( self._send_link_mail(
user.email, user.email,
self._t.transform('api.auth.confirmation.subject').format(user.first_name, user.last_name), 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): def _send_forgot_password_id_to_user(self, user: AuthUser):
@ -232,7 +232,7 @@ class AuthService(AuthServiceABC):
self._db.save_changes() self._db.save_changes()
self._logger.info(__name__, f'Added auth user with E-Mail: {user_dto.email}') self._logger.info(__name__, f'Added auth user with E-Mail: {user_dto.email}')
except Exception as e: 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") raise ServiceException(ServiceErrorCode.UnableToAdd, "Invalid E-Mail")
async def add_auth_user_by_oauth_async(self, dto: OAuthDTO): 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: if db_user.oauth_id != dto.oauth_id:
raise ServiceException(ServiceErrorCode.InvalidUser, 'Wrong OAuthId') raise ServiceException(ServiceErrorCode.InvalidUser, 'Wrong OAuthId')
try:
db_user.first_name = dto.user.first_name db_user.first_name = dto.user.first_name
db_user.last_name = dto.user.last_name db_user.last_name = dto.user.last_name
db_user.password_salt = uuid.uuid4() db_user.password_salt = uuid.uuid4()
db_user.password = self._hash_sha256(dto.user.password, db_user.password_salt) db_user.password = self._hash_sha256(dto.user.password, db_user.password_salt)
db_user.oauth_id = None 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._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() self._db.save_changes()
async def add_auth_user_by_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> OAuthDTO: async def add_auth_user_by_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> OAuthDTO: