Esempio n. 1
0
def _lookup_enforced_session_or_none(request):
    session_ticket = None
    is_observer = False

    if config.GAME_ALLOW_ENFORCED_LOGIN:
        login_data = request.REQUEST.get(ENFORCED_SESSION_TICKET_NAME)
        if login_data:
            try:
                login_data = login_data.encode("ascii", "strict")
                login_data = encryption.unicode_decrypt(login_data) # decode using site's SECRET_KEY
            except (TypeError, ValueError, UnicodeError), e:
                logging.warning("Error when trying to decode enforced ticket: %r" % e)
            else:
                data_list = login_data.split("|")
                if len(data_list) == 2: # LEGACY
                    enforced_instance_id, enforced_login = data_list
                else:
                    assert len(data_list) == 3, data_list
                    enforced_instance_id, enforced_login, is_observer_str = data_list
                    is_observer = bool(is_observer_str) # should be "observer"
                    del is_observer_str
                if enforced_instance_id != request.datamanager.game_instance_id:
                    logging.warning("Wrong game instance id in enforced ticket: %s should contain %s instead", login_data, request.datamanager.game_instance_id)
                else:
                    session_ticket = dict(game_instance_id=enforced_instance_id,
                                          game_username=enforced_login,
                                          impersonation_target=None,
                                          impersonation_writability=None,
                                          is_observer=is_observer)
Esempio n. 2
0
def _lookup_enforced_session_or_none(request):
    session_ticket = None
    is_observer = False

    if config.GAME_ALLOW_ENFORCED_LOGIN:
        login_data_encrypted = request.REQUEST.get(
            ENFORCED_SESSION_TICKET_NAME)
        if login_data_encrypted:
            try:
                login_data = encryption.unicode_decrypt(
                    login_data_encrypted)  # decode using site's SECRET_KEY
            except (TypeError, ValueError, UnicodeError) as e:
                logging.warning(
                    "Error when trying to decode enforced ticket: %r" % e)
            else:
                data_list = login_data.split("|")
                if len(data_list) == 2:  # LEGACY
                    enforced_instance_id, enforced_login = data_list
                else:
                    assert len(data_list) == 3, data_list
                    enforced_instance_id, enforced_login, is_observer_str = data_list
                    is_observer = bool(is_observer_str)  # should be "observer"
                    del is_observer_str
                if enforced_instance_id != request.datamanager.game_instance_id:
                    logging.warning(
                        "Wrong game instance id in enforced ticket: %s should contain %s instead",
                        login_data, request.datamanager.game_instance_id)
                else:
                    session_ticket = dict(
                        game_instance_id=enforced_instance_id,
                        game_username=enforced_login,
                        impersonation_target=None,
                        impersonation_writability=None,
                        is_observer=is_observer)
    return session_ticket
def decode_game_activation_token(activation_token):
    activation_data = encryption.unicode_decrypt(activation_token)
    (game_instance_id, creator_login, creator_email) = activation_data.split("|")
    return (game_instance_id, creator_login, creator_email or None)
def decode_game_activation_token(activation_token):
    activation_data = encryption.unicode_decrypt(activation_token)
    (game_instance_id, creator_login,
     creator_email) = activation_data.split("|")
    return (game_instance_id, creator_login, creator_email or None)