Sunday, February 18, 2018

Re: Handle changing users (e.g. a logout) in a scope/WebSockets

Correct, it's fixed at connection time, much like a Django request object. If you want to vary what user it is, I suggest you just reconnect the websocket when the user logs in or out to make sure you don't have stale data - you should be building for reconnection anyway as network environments will cause them.

Andrew

On Sun, Feb 18, 2018 at 10:59 PM, Daniel Gilge <d.gilge@gmail.com> wrote:
Packages: Channels 2.0, Django 2.0

Hi,

When I understand it correctly a scope's user object isn't updated when a user changes (e.g. logs in or out in another window) for the whole lifetime of the scope. (Please correct me if I am wrong.) Now this can be a serious issue as you can imagine.

What are best practices to deal with that?

My ideas so far:

Logout

I think that's quite easy:
I insert the channel name during connection to a list which is linked to the current user. (I'll probably store that with redis.) I listen to the user_logged_out signal and close all channels of the user after a logout (using the list).

Login

I think I'll do the same here because the JavaScript library should try to reconnect anyway. Then I had a new consumer instance with a new user object. But I'm not sure if this is a good practice.

Alternatively I could update the user object of the scope/every consumer instance concerned. Maybe I could maintain a per user list containing types which perform the user object update. (But I don't know if it's read only or messes things up.)

Other cases

Procedere for is_active, is_anonymous and has_usable_password will be similar to login/logout.

Suggestions are welcome!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60789998-0b64-40a4-9531-6c6f2a168b7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uqNRaDrQ_NdydzKKiKULNbUzRuAonhp4rAmGSF7X-s37w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment