Reject unauthenticated users + exponential wait time
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
758f714096
commit
ea264fbca6
|
@ -47,6 +47,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||||
|
|
||||||
# Fetch the registration of the current user
|
# Fetch the registration of the current user
|
||||||
user = self.scope['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)
|
reg = await Registration.objects.aget(user_id=user.id)
|
||||||
self.registration = reg
|
self.registration = reg
|
||||||
|
|
||||||
|
|
|
@ -736,7 +736,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupSocket() {
|
function setupSocket(nextDelay = 1000) {
|
||||||
// Open a global websocket
|
// Open a global websocket
|
||||||
socket = new WebSocket(
|
socket = new WebSocket(
|
||||||
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
|
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
|
||||||
|
@ -753,7 +753,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
// Manage errors
|
// Manage errors
|
||||||
socket.addEventListener('close', e => {
|
socket.addEventListener('close', e => {
|
||||||
console.error('Chat socket closed unexpectedly, restarting…')
|
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
|
// When the socket is opened, set the language in order to receive alerts in the good language
|
||||||
|
|
Loading…
Reference in New Issue