简体   繁体   English

Django:频道和Web Socket,如何让群聊独占

[英]Django: Channels and Web Socket, how to make group chats exclusive

Eg i have a chat application,例如,我有一个聊天应用程序,

however, i realised that for my application, as long as you have the link to the chat, you can enter.但是,我意识到对于我的应用程序,只要您有聊天链接,就可以进入。 how do I prevent that, and make it such that only members of the group chat can access the chat.我该如何防止这种情况,并使其只有群聊的成员才能访问聊天。 Something like password protected the url to the chat, or perhaps something like whatsapp.诸如密码之类的东西可以保护 url 聊天,或者类似 whatsapp 之类的东西。 Does anyone have any suggestion and reference material as to how I should build this and implement the function?有没有人对我应该如何构建它和实现 function 有任何建议和参考资料? Thank you!谢谢!

I am in the exact same condition as you.What I am thinking of doing is我和你的情况完全一样。我想做的是

Store group_url and the respective user_ids (which we get from django's authentication) in a table(with two columns group_url and allowed_user_ids ) or in Redis .group_url和相应的user_ids (我们从 django 的身份验证中获得)存储在表中(具有两列group_urlallowed_user_ids )或Redis Then when a client connects to a channel,say chat/1234 (where 1234 is the group_url ),we get the id of that user using self.scope['user'].id and check them in the table.然后,当客户端连接到频道时,例如chat/1234 (其中 1234 是group_url ),我们使用self.scope['user'].id获取该用户的 id 并在表中检查它们。 If the user_id is in the respected group_url ,we accept the connection.Else reject the connection.如果user_id在受尊重的group_url中,我们接受连接。否则拒绝连接。 I am new to this too.Suggest me if you find a better approach我也是新手。如果您找到更好的方法,请建议我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM