当前位置: 首页>>代码示例>>Python>>正文


Python EveApiManager.get_characters_from_api方法代码示例

本文整理汇总了Python中services.managers.eve_api_manager.EveApiManager.get_characters_from_api方法的典型用法代码示例。如果您正苦于以下问题:Python EveApiManager.get_characters_from_api方法的具体用法?Python EveApiManager.get_characters_from_api怎么用?Python EveApiManager.get_characters_from_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在services.managers.eve_api_manager.EveApiManager的用法示例。


在下文中一共展示了EveApiManager.get_characters_from_api方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_api_key

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def add_api_key(request):
    logger.debug("add_api_key called by user %s" % request.user)
    user_state = determine_membership_by_user(request.user)
    if request.method == "POST":
        form = UpdateKeyForm(request.POST)
        form.user_state = user_state
        logger.debug("Request type POST with form valid: %s" % form.is_valid())
        if form.is_valid():
            EveManager.create_api_keypair(form.cleaned_data["api_id"], form.cleaned_data["api_key"], request.user)

            # Grab characters associated with the key pair
            characters = EveApiManager.get_characters_from_api(
                form.cleaned_data["api_id"], form.cleaned_data["api_key"]
            )
            EveManager.create_characters_from_list(characters, request.user, form.cleaned_data["api_id"])
            logger.info("Successfully processed api add form for user %s" % request.user)
            return HttpResponseRedirect("/api_key_management/")
        else:
            logger.debug("Form invalid: returning to form.")
    else:
        logger.debug("Providing empty update key form for user %s" % request.user)
        form = UpdateKeyForm()
        form.user_state = user_state
    context = {"form": form, "apikeypairs": EveManager.get_api_key_pairs(request.user.id)}
    return render_to_response("registered/addapikey.html", context, context_instance=RequestContext(request))
开发者ID:kallama,项目名称:allianceauth,代码行数:27,代码来源:views.py

示例2: clean

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
    def clean(self):
        super(UpdateKeyForm, self).clean()

        if 'api_id' in self.cleaned_data and 'api_key' in self.cleaned_data:
            if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
                logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])
                raise forms.ValidationError(u'API key already exist')
            if EveApiManager.api_key_is_valid(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                raise forms.ValidationError(u'API key is invalid')
            chars = EveApiManager.get_characters_from_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']).result
            states = []
            states.append(self.user_state)
            for char in chars:
                evechar = EveCharacter()
                evechar.character_name = chars[char]['name']
                evechar.corporation_id = chars[char]['corp']['id']
                evechar.alliance_id = chars[char]['alliance']['id']
                state = determine_membership_by_character(evechar)
                logger.debug("API ID %s character %s has state %s" % (self.cleaned_data['api_id'], evechar, state))
                states.append(state)

            if 'MEMBER' in states:
                if EveApiManager.validate_member_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                    raise forms.ValidationError(u'API must meet member requirements')
            if 'BLUE' in states:
                if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                    raise forms.ValidationError(u'API must meet blue requirements')
        return self.cleaned_data
开发者ID:Aelonius,项目名称:allianceauth,代码行数:30,代码来源:forms.py

示例3: api_sso_validate

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def api_sso_validate(request, tokens, api_id):
    logger.debug('api_sso_validate called by user %s for api %s' % (request.user, api_id))
    api = get_object_or_404(EveApiKeyPair, api_id=api_id)
    if api.user and api.user != request.user:
        logger.warning('User %s attempting to take ownership of api %s from %s' % (request.user, api_id, api.user))
        messages.warning(request, 'API %s already claimed by user %s' % (api_id, api.user))
        return redirect('auth_api_key_management')
    elif api.sso_verified:
        logger.debug('API %s has already been verified.' % api_id)
        messages.info(request, 'API %s has already been verified' % api_id)
        return redirect('auth_api_key_management')
    token = tokens[0]
    logger.debug('API %s has not been verified. Checking if token for %s matches.' % (api_id, token.character_name))
    characters = EveApiManager.get_characters_from_api(api.api_id, api.api_key).result
    if token.character_id in characters:
        api.user = request.user
        api.sso_verified = True
        api.save()
        EveCharacter.objects.filter(character_id__in=characters).update(user=request.user, api_id=api_id)
        messages.success(request, 'Confirmed ownership of API %s' % api.api_id)
        auth, c = AuthServicesInfo.objects.get_or_create(user=request.user)
        if not auth.main_char_id:
            return redirect('auth_characters')
        return redirect('auth_api_key_management')
    else:
        messages.warning(request, '%s not found on API %s. Please SSO as a character on the API.' % (token.character_name, api.api_id))
    return render(request, 'registered/apisso.html', context={'api':api})
开发者ID:CokkocZateki,项目名称:allianceauth,代码行数:29,代码来源:views.py

示例4: refresh_api

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def refresh_api(api_key_pair):
    logger.debug("Running update on api key %s" % api_key_pair.api_id)
    user = api_key_pair.user
    if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
        #check to ensure API key meets min spec
        logger.info("Determined api key %s is still active." % api_key_pair.api_id)
        still_valid = True
        state = determine_membership_by_user(user)
        if state == "BLUE":
            if settings.BLUE_API_ACCOUNT:
                if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                    logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s is not account-wide as required." % api_key_pair.api_id, level="danger")
                if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                    logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s does not meet access mask requirements." % api_key_pair.api_id, level="danger")
        elif state == "MEMBER":
            if settings.MEMBER_API_ACCOUNT:
                if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                    logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s is not account-wide as required." % api_key_pair.api_id, level="danger")
                if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                    logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s does not meet access mask requirements." % api_key_pair.api_id, level="danger")
        if not still_valid:
           logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
           EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
           EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
           notify(user, "API Key Deleted", message="Your API key ID %s has failed validation. It and its associated characters have been deleted." % api_key_pair.api_id, level="danger")
        else:
           logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
           # Update characters
           characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key)
           EveManager.update_characters_from_list(characters)
           new_character = False
           for char in characters.result:
               # Ensure we have a model for all characters on key
               if not EveManager.check_if_character_exist(characters.result[char]['name']):
                   new_character = True
                   logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name']))
               if new_character:
                   logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id))
                   EveManager.create_characters_from_list(characters, user, api_key_pair.api_id)
           current_chars = EveCharacter.objects.filter(api_id=api_key_pair.api_id)
           for c in current_chars:
               if not int(c.character_id) in characters.result:
                   logger.info("Character %s no longer found on API ID %s" % (c, api_key_pair.api_id))
                   c.delete()
    else:
        logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api_key_pair.api_id)
        EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
        EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
        notify(user, "API Key Deleted", message="Your API key ID %s is invalid. It and its associated characters have been deleted." % api_key_pair.api_id, level="danger")
开发者ID:Geabo,项目名称:allianceauth,代码行数:59,代码来源:tasks.py

示例5: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def run_api_refresh():

    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                if settings.DEBUG:
                    print 'Running update on user: ' + user.username
                if authserviceinfo.main_char_id and authserviceinfo.main_char_id != "":
                    for api_key_pair in api_key_pairs:
                        if settings.DEBUG:
                            print 'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                        if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                            # Update characters
                            characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                               api_key_pair.api_key)
                            EveManager.update_characters_from_list(characters)
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            main_alliance_id = EveManager.get_charater_corporation_id_by_id(
                                authserviceinfo.main_char_id)

                            # NPC corps return as None
                            if main_alliance_id is None or int(main_alliance_id) != int(settings.ALLIANCE_ID):
                                if settings.DEBUG:
                                    print 'Not in Corp'

                                SlackManager.send_director('API ERROR: ' + user.username +
                                                           ' Not in corp.\n\tServices disabled.\n\tAPI removed.')

                                remove_user_all_groups(user)
                                deactivate_services(user)
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                        else:
                            if settings.DEBUG:
                                print 'Bad API Deleting character and api for ' + user.username

                            SlackManager.send_director('API ERROR: Bad API for user ' + user.username +
                                                       '\n\tServices disabled.\n\tAPI removed.')

                            remove_user_all_groups(user)
                            deactivate_services(user)
                            EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                            EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                else:
                    if settings.DEBUG:
                        print 'No main_char_id set'
开发者ID:RZN-FFEvo,项目名称:corpauth,代码行数:56,代码来源:tasks.py

示例6: refresh_api

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def refresh_api(api):
    logger.debug('Running update on api key %s' % api.api_id)
    still_valid = True
    try:
        EveApiManager.validate_api(api.api_id, api.api_key, api.user)
        # Update characters
        characters = EveApiManager.get_characters_from_api(api.api_id, api.api_key)
        EveManager.update_characters_from_list(characters)
        new_character = False
        for char in characters.result:
            # Ensure we have a model for all characters on key
            if not EveManager.check_if_character_exist(characters.result[char]['name']):
                logger.debug(
                    "API key %s has a new character on the account: %s" % (api.api_id, characters.result[char]['name']))
                new_character = True
        if new_character:
            logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api.api_id))
            EveManager.create_characters_from_list(characters, api.user, api.api_id)
        current_chars = EveCharacter.objects.filter(api_id=api.api_id)
        for c in current_chars:
            if not int(c.character_id) in characters.result:
                logger.info("Character %s no longer found on API ID %s" % (c, api.api_id))
                c.delete()
    except evelink.api.APIError as e:
        logger.warning('Received unexpected APIError (%s) while updating API %s' % (e.code, api.api_id))
    except EveApiManager.ApiInvalidError:
        logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api.api_id)
        notify(api.user, "API Failed Validation", message="Your API key ID %s is no longer valid." % api.api_id,
               level="danger")
        still_valid = False
    except EveApiManager.ApiAccountValidationError:
        logger.info(
            "Determined api key %s for user %s no longer meets account access requirements." % (api.api_id, api.user))
        notify(api.user, "API Failed Validation",
               message="Your API key ID %s is no longer account-wide as required." % api.api_id, level="danger")
        still_valid = False
    except EveApiManager.ApiMaskValidationError as e:
        logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (
            api.api_id, api.user))
        notify(api.user, "API Failed Validation",
               message="Your API key ID %s no longer meets access mask requirements. Required: %s Got: %s" % (
                   api.api_id, e.required_mask, e.api_mask), level="danger")
        still_valid = False
    except EveApiManager.ApiServerUnreachableError as e:
        logger.warn("Error updating API %s\n%s" % (api.api_id, str(e)))
    finally:
        if not still_valid:
            EveManager.delete_characters_by_api_id(api.api_id, api.user.id)
            EveManager.delete_api_key_pair(api.api_id, api.user.id)
            notify(api.user, "API Key Deleted",
                   message="Your API key ID %s is invalid. It and its associated characters have been deleted." % api.api_id,
                   level="danger")
开发者ID:CokkocZateki,项目名称:allianceauth,代码行数:54,代码来源:tasks.py

示例7: add_api_key

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def add_api_key(request):
    logger.debug("add_api_key called by user %s" % request.user)
    if request.method == 'POST':
        form = UpdateKeyForm(request.user, request.POST)
        logger.debug("Request type POST with form valid: %s" % form.is_valid())
        if form.is_valid():
            if EveApiKeyPair.objects.filter(api_id=form.cleaned_data['api_id'],
                                            api_key=form.cleaned_data['api_key']).exists():
                # allow orphaned keys to proceed to SSO validation upon re-entry
                api_key = EveApiKeyPair.objects.get(api_id=form.cleaned_data['api_id'],
                                                   api_key=form.cleaned_data['api_key'])
            elif EveApiKeyPair.objects.filter(api_id=form.cleaned_data['api_id']).exists():
                logger.warn('API %s re-added with different vcode.' % form.cleaned_data['api_id'])
                EveApiKeyPair.objects.filter(api_id=form.cleaned_data['api_id']).delete()
                api_key = EveApiKeyPair.objects.create(api_id=form.cleaned_data['api_id'],
                                                       api_key=form.cleaned_data['api_key'])
            else:
                api_key = EveApiKeyPair.objects.create(api_id=form.cleaned_data['api_id'],
                                                       api_key=form.cleaned_data['api_key'])
            owner = None
            if not settings.API_SSO_VALIDATION:
                # set API and character owners if SSO validation not requested
                api_key.user = request.user
                api_key.save()
                owner = request.user
            # Grab characters associated with the key pair
            characters = EveApiManager.get_characters_from_api(form.cleaned_data['api_id'],
                                                               form.cleaned_data['api_key'])
            EveManager.create_characters_from_list(characters, owner, form.cleaned_data['api_id'])
            logger.info("Successfully processed api add form for user %s" % request.user)
            if not settings.API_SSO_VALIDATION:
                messages.success(request, 'Added API key %s to your account.' % form.cleaned_data['api_id'])
                auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0]
                if not auth.main_char_id:
                    return redirect('auth_characters')
                return redirect("/api_key_management/")
            else:
                logger.debug('Requesting SSO validation of API %s by user %s' % (api_key.api_id, request.user))
                return render(request, 'registered/apisso.html', context={'api':api_key})
        else:
            logger.debug("Form invalid: returning to form.")
    else:
        logger.debug("Providing empty update key form for user %s" % request.user)
        form = UpdateKeyForm(request.user)
    context = {'form': form, 'apikeypairs': EveManager.get_api_key_pairs(request.user.id)}
    return render(request, 'registered/addapikey.html', context=context)
开发者ID:CokkocZateki,项目名称:allianceauth,代码行数:48,代码来源:views.py

示例8: clean

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
    def clean(self):
        super(UpdateKeyForm, self).clean()

        if "api_id" in self.cleaned_data and "api_key" in self.cleaned_data:
            try:
                if EveManager.check_if_api_key_pair_exist(self.cleaned_data["api_id"]):
                    logger.debug(
                        "UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data["api_id"]
                    )
                    raise forms.ValidationError(u"API key already exist")
                if EveApiManager.api_key_is_valid(self.cleaned_data["api_id"], self.cleaned_data["api_key"]) is False:
                    raise forms.ValidationError(u"API key is invalid")
                chars = EveApiManager.get_characters_from_api(
                    self.cleaned_data["api_id"], self.cleaned_data["api_key"]
                ).result
                states = []
                states.append(self.user_state)
                for char in chars:
                    evechar = EveCharacter()
                    evechar.character_name = chars[char]["name"]
                    evechar.corporation_id = chars[char]["corp"]["id"]
                    evechar.alliance_id = chars[char]["alliance"]["id"]
                    state = determine_membership_by_character(evechar)
                    logger.debug("API ID %s character %s has state %s" % (self.cleaned_data["api_id"], evechar, state))
                    states.append(state)

                if "MEMBER" in states:
                    if (
                        EveApiManager.validate_member_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
                        is False
                    ):
                        raise forms.ValidationError(u"API must meet member requirements")
                if "BLUE" in states:
                    if (
                        EveApiManager.validate_blue_api(self.cleaned_data["api_id"], self.cleaned_data["api_key"])
                        is False
                    ):
                        raise forms.ValidationError(u"API must meet blue requirements")
                return self.cleaned_data
            except evelink.api.APIError as e:
                logger.debug("Got error code %s while validating API %s" % (e.code, self.cleaned_data["api_id"]))
                if int(e.code) in [221, 222]:
                    raise forms.ValidationError("API key failed validation")
                else:
                    raise forms.ValidationError("Failed to reach API servers")
开发者ID:Ydmir,项目名称:allianceauth,代码行数:47,代码来源:forms.py

示例9: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def run_api_refresh():
    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                print 'Running update on user: ' + user.username
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        for api_key_pair in api_key_pairs:
                            print 'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                # Update characters
                                characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                   api_key_pair.api_key)
                                EveManager.update_characters_from_list(characters)
                                valid_key = True
                            else:
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, api_key_pair.api_key)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                            main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                            if main_alliance_id == settings.ALLIANCE_ID:
                                pass
                            elif corp is not None:
                                if corp.is_blue is not True:
                                    deactivate_services(user)
                            else:
                                deactivate_services(user)
                        else:
                            # nuke it
                            deactivate_services(user)
                else:
                    print 'No main_char_id set'
开发者ID:Krienas,项目名称:allianceauth,代码行数:45,代码来源:tasks.py

示例10: add_api_key

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def add_api_key(request):
    if request.method == 'POST':
        form = UpdateKeyForm(request.POST)

        if form.is_valid():
            EveManager.create_api_keypair(form.cleaned_data['api_id'],
                                          form.cleaned_data['api_key'],
                                          request.user)

            # Grab characters associated with the key pair
            characters = EveApiManager.get_characters_from_api(form.cleaned_data['api_id'],
                                                               form.cleaned_data['api_key'])
            EveManager.create_characters_from_list(characters, request.user, form.cleaned_data['api_id'])
            return HttpResponseRedirect("/api_key_management/")
    else:
        form = UpdateKeyForm()
    context = {'form': form, 'apikeypairs': EveManager.get_api_key_pairs(request.user.id)}
    return render_to_response('registered/addapikey.html', context,
                              context_instance=RequestContext(request))
开发者ID:Krienas,项目名称:allianceauth,代码行数:21,代码来源:views.py

示例11: clean

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
    def clean(self):
        super(UpdateKeyForm, self).clean()

        if 'api_id' in self.cleaned_data and 'api_key' in self.cleaned_data:
            try:
                if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
                    logger.debug("UpdateKeyForm failed cleaning as API id %s already exists." % self.cleaned_data['api_id'])
                    raise forms.ValidationError(u'API key already exist')
                if EveApiManager.api_key_is_valid(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                    raise forms.ValidationError(u'API key is invalid')
                if (settings.REJECT_OLD_APIS and
                    EveManager.check_if_api_key_pair_is_new(self.cleaned_data['api_id'], settings.REJECT_OLD_APIS_MARGIN) is False):
                    raise forms.ValidationError(u'API key is too old. Please create a new key')
                chars = EveApiManager.get_characters_from_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']).result
                states = []
                states.append(self.user_state)
                for char in chars:
                    evechar = EveCharacter()
                    evechar.character_name = chars[char]['name']
                    evechar.corporation_id = chars[char]['corp']['id']
                    evechar.alliance_id = chars[char]['alliance']['id']
                    state = determine_membership_by_character(evechar)
                    logger.debug("API ID %s character %s has state %s" % (self.cleaned_data['api_id'], evechar, state))
                    states.append(state)

                if 'MEMBER' in states:
                    if EveApiManager.validate_member_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                        raise forms.ValidationError(u'API must meet member requirements')
                if 'BLUE' in states:
                    if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                        raise forms.ValidationError(u'API must meet blue requirements')
                if 'BLUE_10' in states:
                    if EveApiManager.validate_blue_api(self.cleaned_data['api_id'], self.cleaned_data['api_key']) is False:
                        raise forms.ValidationError(u'API must meet blue requirements')
                return self.cleaned_data
            except evelink.api.APIError as e:
                logger.debug("Got error code %s while validating API %s" % (e.code, self.cleaned_data['api_id']))
                if int(e.code) in [221, 222]:
                    raise forms.ValidationError("API key failed validation")
                else:
                    raise forms.ValidationError("Failed to reach API servers")
开发者ID:RichterSR,项目名称:allianceauth,代码行数:43,代码来源:forms.py

示例12: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]

#.........这里部分代码省略.........
                                still_valid = None
                            elif full == False:
                                logger.info(
                                    "Determined api key %s for blue user %s no longer meets minimum access mask as required."
                                    % (api_key_pair.api_id, user)
                                )
                                still_valid = False
                        elif state == "MEMBER":
                            if settings.MEMBER_API_ACCOUNT:
                                type = EveApiManager.check_api_is_type_account(
                                    api_key_pair.api_id, api_key_pair.api_key
                                )
                                if type == None:
                                    api_key_pair.error_count += 1
                                    api_key_pair.save()
                                    logger.info(
                                        "API key %s incurred an error checking if type account. Error count is now %s"
                                        % (api_key_pair.api_id, api_key_pair.error_count)
                                    )
                                    still_valid = None
                                elif type == False:
                                    logger.info(
                                        "Determined api key %s for user %s is no longer type account as required."
                                        % (api_key_pair.api_id, user)
                                    )
                                    still_valid = False
                            full = EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
                            if full == None:
                                api_key_pair.error_count += 1
                                api_key_pair.save()
                                logger.info(
                                    "API key %s incurred an error checking if meets mask requirements. Error count is now %s"
                                    % (api_key_pair.api_id, api_key_pair.error_count)
                                )
                                still_valid = None
                            elif full == False:
                                logger.info(
                                    "Determined api key %s for user %s no longer meets minimum access mask as required."
                                    % (api_key_pair.api_id, user)
                                )
                                still_valid = False
                        if still_valid == None:
                            if api_key_pair.error_count >= 3:
                                logger.info(
                                    "API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id
                                )
                                still_valid = False
                        if still_valid == False:
                            logger.debug(
                                "API key %s has failed validation; it and its characters will be deleted."
                                % api_key_pair.api_id
                            )
                            EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                            EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                        elif still_valid == True:
                            if api_key_pair.error_count != 0:
                                logger.info(
                                    "Clearing error count for api %s as it passed validation" % api_key_pair.api_id
                                )
                                api_key_pair.error_count = 0
                                api_key_pair.save()
                            logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
                            # Update characters
                            characters = EveApiManager.get_characters_from_api(
                                api_key_pair.api_id, api_key_pair.api_key
                            )
                            EveManager.update_characters_from_list(characters)
                            new_character = False
                            for char in characters.result:
                                # Ensure we have a model for all characters on key
                                if not EveManager.check_if_character_exist(characters.result[char]["name"]):
                                    new_character = True
                                    logger.debug(
                                        "API key %s has a new character on the account: %s"
                                        % (api_key_pair.api_id, characters.result[char]["name"])
                                    )
                            if new_character:
                                logger.debug(
                                    "Creating new character %s from api key %s"
                                    % (characters.result[char]["name"], api_key_pair.api_id)
                                )
                                EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                    else:
                        logger.debug(
                            "API key %s is no longer valid; it and its characters will be deleted."
                            % api_key_pair.api_id
                        )
                        EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                        EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                # Check our main character
                if EveCharacter.objects.filter(character_id=authserviceinfo.main_char_id).exists() is False:
                    logger.info(
                        "User %s main character id %s missing model. Clearning main character."
                        % (user, authserviceinfo.main_char_id)
                    )
                    authserviceinfo.main_char_id = ""
                    authserviceinfo.save()
                else:
                    logger.warn("User %s has no main character id, unable to validate membership.")
        set_state(user)
开发者ID:kallama,项目名称:allianceauth,代码行数:104,代码来源:tasks.py

示例13: run_api_refresh

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        #preserve old corp ID for corp change test on members
                        oldcorp_id = 0
                        if EveManager.get_character_by_id(authserviceinfo.main_char_id):
                            oldcorp_id = EveCharacter.objects.get(character_id=authserviceinfo.main_char_id).corporation_id
                            logger.debug("Determined user %s current main corp id %s" % (user, oldcorp_id))
                        for api_key_pair in api_key_pairs:
                            logger.debug("Running update on api key %s" % api_key_pair.api_id)
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                #check to ensure API key meets min spec
                                logger.info("Determined api key %s is still active." % api_key_pair.api_id)
                                still_valid = True
                                if authserviceinfo.is_blue:
                                    if settings.BLUE_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                else:
                                    if settings.MEMBER_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                if still_valid is not True:
                                    logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
                                    EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                    EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                                else:
                                    logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
                                    # Update characters
                                    characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                       api_key_pair.api_key)
                                    EveManager.update_characters_from_list(characters)
                                    new_character = False
                                    for char in characters.result:
                                        # Ensure we have a model for all characters on key
                                        if not EveManager.check_if_character_exist(characters.result[char]['name']):
                                            new_character = True
                                            logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name']))
                                    if new_character:
                                        logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id))
                                        EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                                    valid_key = True
                            else:
                                logger.debug("API key %s is no longer active; it and its characters will be deleted." % api_key_pair.api_id)
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            logger.debug("User %s has valid api key, checking main character %s" % (user, character))
                            if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id):
                                corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                                main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id)
                                main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                                logger.debug("User %s main character %s has corp %s with alliance id %s" % (user, character, corp, main_alliance_id))
                                if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID):
                                    logger.debug("User %s corp or alliance meets membership requirements. Ensuring has required permissions and groups." % user)
                                    if not check_if_user_has_permission(user, "member"):
                                        #transition from none or blue to member
                                        if check_if_user_has_permission(user, "blue_member"):
                                            #strip blue status
                                            logger.debug("Removing user %s blue permission and group to prepare for member transition." % user)
                                            remove_member_permission(user, "blue_member")
                                            remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(False, user)
                                        #add to auth group
                                        add_member_permission(user, "member")
                                        add_user_to_group(user, settings.DEFAULT_AUTH_GROUP)
                                        #add to required corp group
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        logger.info("User %s transitioned to full member during api refresh." % user)
                                    elif corp.corporation_id != oldcorp_id:
                                        #changed corps, both corps auth'd, need to change group assignment
                                        logger.debug("User %s main character changed corp from id %s to %s, both meet membership requirements. Updating corp group." % (user, oldcorp_id, corp.corporation_id))
                                        oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id)
                                        remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name))
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        #reset services to force new mumble names and group assignments
#.........这里部分代码省略.........
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:103,代码来源:tasks.py

示例14: get_characters_from_api

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
 def get_characters_from_api(api):
     char_result = EveApiManager.get_characters_from_api(api.api_id, api.api_key).result
     provider = EveXmlProvider(adapter=EveManager.get_adapter())
     return [provider._build_character(result) for id, result in char_result.items()]
开发者ID:CreoTEK,项目名称:allianceauth,代码行数:6,代码来源:managers.py

示例15: refresh_api

# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_characters_from_api [as 别名]
def refresh_api(api_key_pair):
    logger.debug("Running update on api key %s" % api_key_pair.api_id)
    user = api_key_pair.user
    if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
        #check to ensure API key meets min spec
        logger.info("Determined api key %s is still active." % api_key_pair.api_id)
        still_valid = True
        state = determine_membership_by_user(user)
        if state == "BLUE":
            if settings.BLUE_API_ACCOUNT:
                type = EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key)
                if type == None:
                    api_key_pair.error_count += 1
                    api_key_pair.save()
                    logger.info("API key %s incurred an error checking if type account. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
                    still_valid = None
                elif type == False:
                    logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s is not account-wide as required." % api_key_pair.api_id, level="danger")
                full = EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
                if full == None:
                    api_key_pair.error_count += 1
                    api_key_pair.save()
                    logger.info("API key %s incurred an error checking if meets mask requirements. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
                    still_valid = None
                elif full == False:
                    logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s does not meet access mask requirements." % api_key_pair.api_id, level="danger")
        elif state == "MEMBER":
            if settings.MEMBER_API_ACCOUNT:
                type = EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key)
                if type == None:
                    api_key_pair.error_count += 1
                    api_key_pair.save()
                    logger.info("API key %s incurred an error checking if type account. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
                    still_valid = None
                elif type == False:
                    logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s is not account-wide as required." % api_key_pair.api_id, level="danger")
                full = EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
                if full == None:
                    api_key_pair.error_count += 1
                    api_key_pair.save()
                    logger.info("API key %s incurred an error checking if meets mask requirements. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
                    still_valid = None
                elif full == False:
                    logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                    still_valid = False
                    notify(user, "API Failed Validation", message="Your API key ID %s does not meet access mask requirements." % api_key_pair.api_id, level="danger")
        if still_valid == None:
               if api_key_pair.error_count >= 3:
                   logger.info("API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id)
                   still_valid = False
                   notify(user, "API Failed Validation", message="Your API key ID %s has accumulated too many errors during refresh and is assumed to be invalid." % api_key_pair.api_id, level="danger")
        if still_valid == False:
               logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
               EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
               EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
               notify(user, "API Key Deleted", message="Your API key ID %s has failed validation. It and its associated characters have been deleted." % api_key_pair.api_id, level="danger")
        elif still_valid == True:
               if api_key_pair.error_count != 0:
                   logger.info("Clearing error count for api %s as it passed validation" % api_key_pair.api_id)
                   api_key_pair.error_count = 0
                   api_key_pair.save()
               logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
               # Update characters
               characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key)
               EveManager.update_characters_from_list(characters)
               new_character = False
               for char in characters.result:
                   # Ensure we have a model for all characters on key
                   if not EveManager.check_if_character_exist(characters.result[char]['name']):
                       new_character = True
                       logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name']))
                   if new_character:
                       logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id))
                       EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
    else:
        logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api_key_pair.api_id)
        EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
        EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
        notify(user, "API Key Deleted", message="Your API key ID %s is invalid. It and its associated characters have been deleted." % api_key_pair.api_id, level="danger")
开发者ID:Aelonius,项目名称:allianceauth,代码行数:87,代码来源:tasks.py


注:本文中的services.managers.eve_api_manager.EveApiManager.get_characters_from_api方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。