This commit is contained in:
parent
993113b2b7
commit
005b3f4530
13 changed files with 114 additions and 64 deletions
|
|
@ -68,13 +68,14 @@ def general_context(request):
|
|||
is automatically added to context of all views.
|
||||
"""
|
||||
account = None
|
||||
if request.user.is_authenticated: account = request.user
|
||||
if request.user.is_authenticated:
|
||||
account = request.user
|
||||
|
||||
puppet = None
|
||||
if account and request.session.get('puppet'):
|
||||
pk = int(request.session.get('puppet'))
|
||||
puppet = next((x for x in account.characters if x.pk == pk), None)
|
||||
|
||||
|
||||
return {
|
||||
'account': account,
|
||||
'puppet': puppet,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from django.contrib.auth import authenticate, login
|
|||
from evennia.accounts.models import AccountDB
|
||||
from evennia.utils import logger
|
||||
|
||||
|
||||
class SharedLoginMiddleware(object):
|
||||
"""
|
||||
Handle the shared login between website and webclient.
|
||||
|
|
@ -10,47 +11,47 @@ class SharedLoginMiddleware(object):
|
|||
def __init__(self, get_response):
|
||||
# One-time configuration and initialization.
|
||||
self.get_response = get_response
|
||||
|
||||
|
||||
def __call__(self, request):
|
||||
# Code to be executed for each request before
|
||||
# the view (and later middleware) are called.
|
||||
|
||||
|
||||
# Synchronize credentials between webclient and website
|
||||
# Must be performed *before* rendering the view (issue #1723)
|
||||
self.make_shared_login(request)
|
||||
|
||||
|
||||
# Process view
|
||||
response = self.get_response(request)
|
||||
|
||||
# Code to be executed for each request/response after
|
||||
# the view is called.
|
||||
|
||||
|
||||
# Return processed view
|
||||
return response
|
||||
|
||||
|
||||
@classmethod
|
||||
def make_shared_login(cls, request):
|
||||
csession = request.session
|
||||
account = request.user
|
||||
website_uid = csession.get("website_authenticated_uid", None)
|
||||
webclient_uid = csession.get("webclient_authenticated_uid", None)
|
||||
|
||||
|
||||
if not csession.session_key:
|
||||
# this is necessary to build the sessid key
|
||||
csession.save()
|
||||
|
||||
|
||||
if account.is_authenticated:
|
||||
# Logged into website
|
||||
if not website_uid:
|
||||
if website_uid is None:
|
||||
# fresh website login (just from login page)
|
||||
csession["website_authenticated_uid"] = account.id
|
||||
if webclient_uid is None:
|
||||
# auto-login web client
|
||||
csession["webclient_authenticated_uid"] = account.id
|
||||
|
||||
if webclient_uid is None:
|
||||
# auto-login web client
|
||||
csession["webclient_authenticated_uid"] = account.id
|
||||
|
||||
elif webclient_uid:
|
||||
# Not logged into website, but logged into webclient
|
||||
if not website_uid:
|
||||
if website_uid is None:
|
||||
csession["website_authenticated_uid"] = account.id
|
||||
account = AccountDB.objects.get(id=webclient_uid)
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue