def cached_ui_info_for_hero(cls, account_id, recache_if_required, patch_turns, for_last_turn): from . import logic data = cache.get(cls.cached_ui_info_key_for_hero(account_id)) if data is None: hero = logic.load_hero(account_id=account_id) data = hero.ui_info(actual_guaranteed=False) cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn) if recache_if_required and cls.is_ui_continue_caching_required(data['ui_caching_started_at']) and GameState.is_working(): amqp_environment.environment.workers.supervisor.cmd_start_hero_caching(account_id) if patch_turns is not None and data['patch_turn'] in patch_turns: patch_fields = set(data['changed_fields']) for field in data.keys(): if field not in patch_fields: del data[field] else: data['patch_turn'] = None del data['changed_fields'] return data
def cached_ui_info_for_hero(cls, account_id, recache_if_required, patch_turns, for_last_turn): data = cache.get(cls.cached_ui_info_key_for_hero(account_id)) if data is None: hero = cls.get_by_account_id(account_id) data = hero.ui_info(actual_guaranteed=False) cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn) if recache_if_required and cls.is_ui_continue_caching_required( data['ui_caching_started_at']) and GameState.is_working(): environment.workers.supervisor.cmd_start_hero_caching(account_id) if patch_turns is not None and data['patch_turn'] in patch_turns: patch_fields = set(data['changed_fields']) for field in data.keys(): if field not in patch_fields: del data[field] else: data['patch_turn'] = None del data['changed_fields'] return data
def handle_third_party(self, request): if third_party_settings.ACCESS_TOKEN_SESSION_KEY not in request.session: return HANDLE_THIRD_PARTY_RESULT.NO_ACCESS_TOKEN access_token_uid = request.session[ third_party_settings.ACCESS_TOKEN_SESSION_KEY] cache_key = third_party_settings.ACCESS_TOKEN_CACHE_KEY % access_token_uid cached_data = cache.get(cache_key) if cached_data is None: access_token = prototypes.AccessTokenPrototype.get_by_uid( access_token_uid) if access_token is None: if request.user.is_authenticated(): accounts_logic.logout_user(request) request.session[ third_party_settings. ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_REJECTED__LOGOUT else: return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_REJECTED else: cached_data = access_token.cache_data() cache.set(cache_key, cached_data, third_party_settings.ACCESS_TOKEN_CACHE_TIMEOUT) account_id = cached_data['account_id'] if account_id is None: if request.user.is_authenticated(): accounts_logic.logout_user(request) # resave token, since it will be removed on logout request.session[third_party_settings. ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_NOT_ACCEPTED_YET if not request.user.is_authenticated( ) or request.user.id != account_id: account = AccountPrototype.get_by_id(account_id) accounts_logic.force_login_user(request, account._model) # resave token, since it will be removed on login request.session[third_party_settings. ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_ACCEPTED__USER_LOGED_IN return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_ACCEPTED
def handle_third_party(self, request): if third_party_settings.ACCESS_TOKEN_SESSION_KEY not in request.session: return HANDLE_THIRD_PARTY_RESULT.NO_ACCESS_TOKEN access_token_uid = request.session[third_party_settings.ACCESS_TOKEN_SESSION_KEY] cache_key = third_party_settings.ACCESS_TOKEN_CACHE_KEY % access_token_uid cached_data = cache.get(cache_key) if cached_data is None: access_token = prototypes.AccessTokenPrototype.get_by_uid(access_token_uid) if access_token is None: if request.user.is_authenticated(): accounts_logic.logout_user(request) request.session[third_party_settings.ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_REJECTED__LOGOUT else: return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_REJECTED else: cached_data = access_token.cache_data() cache.set(cache_key, cached_data, third_party_settings.ACCESS_TOKEN_CACHE_TIMEOUT) account_id = cached_data['account_id'] if account_id is None: if request.user.is_authenticated(): accounts_logic.logout_user(request) # resave token, since it will be removed on logout request.session[third_party_settings.ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_NOT_ACCEPTED_YET if not request.user.is_authenticated() or request.user.id != account_id: account = AccountPrototype.get_by_id(account_id) accounts_logic.force_login_user(request, account._model) # resave token, since it will be removed on login request.session[third_party_settings.ACCESS_TOKEN_SESSION_KEY] = access_token_uid return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_ACCEPTED__USER_LOGED_IN return HANDLE_THIRD_PARTY_RESULT.ACCESS_TOKEN_ACCEPTED