mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Check the AccountStatus API to see if a account is still usable
This commit is contained in:
@@ -8,6 +8,7 @@ API_STATUS_AUTH_ERROR = 2
|
||||
API_STATUS_OTHER_ERROR = 3
|
||||
API_STATUS_ACC_EXPIRED = 4
|
||||
API_STATUS_KEY_EXPIRED = 5
|
||||
API_STATUS_INVALID_PERMISSIONS = 6
|
||||
|
||||
# This tuple is used to assemble the choices list for the field.
|
||||
API_STATUS_CHOICES = (
|
||||
@@ -17,6 +18,7 @@ API_STATUS_CHOICES = (
|
||||
(API_STATUS_OTHER_ERROR, 'Other Error'),
|
||||
(API_STATUS_ACC_EXPIRED, 'Account Expired'),
|
||||
(API_STATUS_KEY_EXPIRED, 'Key Expired'),
|
||||
(API_STATUS_INVALID_PERMISSIONS, 'Invalid Permissions'),
|
||||
)
|
||||
|
||||
API_KEYTYPE_UNKNOWN = 0
|
||||
|
||||
@@ -7,6 +7,8 @@ from celery.decorators import task
|
||||
from celery.task.sets import TaskSet
|
||||
from gargoyle import gargoyle
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from eve_proxy.exceptions import *
|
||||
from eve_proxy.models import CachedDocument
|
||||
|
||||
@@ -111,10 +113,27 @@ def import_apikey_func(api_userid, api_key, user=None, force_cache=False, log=lo
|
||||
account.api_keytype = API_KEYTYPE_CORPORATION
|
||||
elif keydoc['type'] == 'Account':
|
||||
account.api_keytype = API_KEYTYPE_ACCOUNT
|
||||
account.api_accessmask = keydoc['accessMask']
|
||||
account.api_accessmask = int(keydoc['accessMask'])
|
||||
if not keydoc['expires'] == '':
|
||||
account.api_expiry = datetime.strptime(keydoc['expires'], '%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# Checks account status to see if the account is still active
|
||||
if not account.api_keytype == API_KEYTYPE_CORPORATION:
|
||||
|
||||
if account.has_access(25):
|
||||
status = CachedDocument.objects.api_query('/account/AccountStatus.xml.aspx', params=auth_params, no_cache=True)
|
||||
status = basic_xml_parse_doc(status)['eveapi']
|
||||
if not status.get('error', None):
|
||||
paiddate = datetime.strptime(status['result']['paidUntil'], '%Y-%m-%d %H:%M:%S')
|
||||
if paiddate <= datetime.utcnow():
|
||||
account.api_status = API_STATUS_ACC_EXPIRED
|
||||
else:
|
||||
account.api_status = API_STATUS_OK
|
||||
else:
|
||||
account.api_status = API_STATUS_INVALID_PERMISSIONS
|
||||
|
||||
if not account.check_access(getattr(settings, 'EVE_API_MINIMUM_KEYMASK', 59638024)):
|
||||
account.api_status = API_STATUS_INVALID_PERMISSIONS
|
||||
|
||||
# Remove deleted or traded characters
|
||||
newcharlist = [int(char['characterID']) for char in doc['result']['key']['characters']]
|
||||
@@ -147,6 +166,8 @@ def import_apikey_func(api_userid, api_key, user=None, force_cache=False, log=lo
|
||||
account.api_status = API_STATUS_ACC_EXPIRED
|
||||
elif error in ['222', '223']:
|
||||
account.api_status = API_STATUS_KEY_EXPIRED
|
||||
elif error in ['221']:
|
||||
account.api_status = API_STATUS_INVALID_PERMISSIONS
|
||||
else:
|
||||
account.api_status = API_STATUS_OTHER_ERROR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user