I've got some nifty code that on user login, finds any other user logged in as that user and logs them out. It works just fine, but it doesn't offer any indication as to why these people are no longer logged in, so I'm trying to remedy that with Django's messaging system.
You've been logged out because somebody has been sharing their login credentials.
Don't do that, it's uncool.
The only problem is that message.error()
(understandably) requires request
as the first argument, and at the point at which I'm kicking other users, I don't have their request objects, I only have the kicking user's object.
So I'm working on options. I suppose I could write a model to log these sorts of messages, keyed by session id (which I have from every user), and then some middleware that checks the db for any messages for that session id on every request but that seems really wasteful, not to mention anti-DRY. There must be a better way to do it, but I don't know what it is yet.