mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-02 18:47:10 -05:00 
			
		
		
		
	websocket authentication
This commit is contained in:
		
							parent
							
								
									c36fe577de
								
							
						
					
					
						commit
						ba3c8308b3
					
				@ -1,14 +1,19 @@
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from asgiref.sync import async_to_sync
 | 
					from asgiref.sync import async_to_sync
 | 
				
			||||||
 | 
					from channels.exceptions import DenyConnection, AcceptConnection
 | 
				
			||||||
from channels.generic.websocket import WebsocketConsumer
 | 
					from channels.generic.websocket import WebsocketConsumer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class StatusConsumer(WebsocketConsumer):
 | 
					class StatusConsumer(WebsocketConsumer):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def connect(self):
 | 
					    def connect(self):
 | 
				
			||||||
        self.accept()
 | 
					        if not self.scope['user'].is_authenticated:
 | 
				
			||||||
 | 
					            raise DenyConnection()
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
            async_to_sync(self.channel_layer.group_add)(
 | 
					            async_to_sync(self.channel_layer.group_add)(
 | 
				
			||||||
                'status_updates', self.channel_name)
 | 
					                'status_updates', self.channel_name)
 | 
				
			||||||
 | 
					            raise AcceptConnection()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def disconnect(self, close_code):
 | 
					    def disconnect(self, close_code):
 | 
				
			||||||
        async_to_sync(self.channel_layer.group_discard)(
 | 
					        async_to_sync(self.channel_layer.group_discard)(
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user