Compare commits

...

4 Commits

Author SHA1 Message Date
Emmy D'Anello ec0419a6d7
Fix expected GDrive channel ID
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-06 22:43:48 +02:00
Emmy D'Anello 54016a1fbf
Remove test code
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-06 22:37:33 +02:00
Emmy D'Anello 7ae015cef9
Reject unauthenticated users + exponential wait time
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-06 22:31:52 +02:00
Emmy D'Anello ea264fbca6
Reject unauthenticated users + exponential wait time
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-06 22:25:58 +02:00
3 changed files with 12 additions and 4 deletions

View File

@ -47,6 +47,11 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
# Fetch the registration of the current user
user = self.scope['user']
if user.is_anonymous:
# User is not authenticated
await self.close()
return
reg = await Registration.objects.aget(user_id=user.id)
self.registration = reg
@ -71,6 +76,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
Called when the websocket got disconnected, for any reason.
:param close_code: The error code.
"""
if self.scope['user'].is_anonymous:
# User is not authenticated
return
# Unregister from channel layers
if not self.registration.is_volunteer:
await self.channel_layer.group_discard(f"team-{self.registration.team.trigram}", self.channel_name)

View File

@ -736,7 +736,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
function setupSocket() {
function setupSocket(nextDelay = 1000) {
// Open a global websocket
socket = new WebSocket(
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
@ -753,7 +753,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Manage errors
socket.addEventListener('close', e => {
console.error('Chat socket closed unexpectedly, restarting…')
setupSocket()
setTimeout(() => setupSocket(2 * nextDelay), nextDelay)
})
// When the socket is opened, set the language in order to receive alerts in the good language

View File

@ -1886,8 +1886,7 @@ class GSheetNotificationsView(View):
return HttpResponse(status=404)
tournament = await Tournament.objects.prefetch_related('participations', 'pools').aget(pk=kwargs['pk'])
request.site.domain = "test.ynerant.fr"
expected_channel_id = sha1(f"{tournament.name}{timezone.now().date()}{request.site.domain}".encode()) \
expected_channel_id = sha1(f"{tournament.name}-{timezone.now().date()}-{request.site.domain}".encode()) \
.hexdigest()
if request.headers['X-Goog-Channel-ID'] != expected_channel_id: