mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Fixes Issue #27, woohoo!
This commit is contained in:
@@ -8,12 +8,7 @@ from eve_api.api_puller.accounts import import_eve_account
|
||||
|
||||
def account_api_update(modeladmin, request, queryset):
|
||||
for obj in queryset:
|
||||
try:
|
||||
import_eve_account(obj.api_key, obj.api_user_id)
|
||||
obj.api_status = 1
|
||||
except APIAuthException:
|
||||
obj.api_status = 2
|
||||
obj.save()
|
||||
|
||||
account_api_update.short_description = "Update account from the EVE API"
|
||||
|
||||
|
||||
@@ -23,9 +23,27 @@ def import_eve_account(api_key, user_id):
|
||||
Imports an account from the API into the EVEAccount model.
|
||||
"""
|
||||
auth_params = {'userID': user_id, 'apiKey': api_key}
|
||||
|
||||
try:
|
||||
account_doc = CachedDocument.objects.api_query('/account/Characters.xml.aspx',
|
||||
params=auth_params,
|
||||
no_cache=False)
|
||||
except APIAuthException:
|
||||
try:
|
||||
account = EVEAccount.objects.get(id=user_id)
|
||||
except EVEAccount.DoesNotExist:
|
||||
return
|
||||
if api_key == account.api_key:
|
||||
account.api_status = API_STATUS_AUTH_ERROR
|
||||
account.api_last_updated = datetime.utcnow()
|
||||
account.save()
|
||||
return
|
||||
except APINoUserIDException:
|
||||
try:
|
||||
account = EVEAccount.objects.get(id=user_id)
|
||||
account.delete()
|
||||
except EVEAccount.DoesNotExist:
|
||||
return
|
||||
|
||||
dom = minidom.parseString(account_doc.body.encode('utf-8'))
|
||||
|
||||
@@ -52,8 +70,6 @@ def import_eve_account(api_key, user_id):
|
||||
account.api_key = api_key
|
||||
account.api_user_id = user_id
|
||||
account.api_status = API_STATUS_OK
|
||||
account.api_last_updated = datetime.utcnow()
|
||||
account.save()
|
||||
|
||||
for node in characters_node_children:
|
||||
try:
|
||||
@@ -63,6 +79,9 @@ def import_eve_account(api_key, user_id):
|
||||
except AttributeError:
|
||||
# This must be a Text node, ignore it.
|
||||
continue
|
||||
|
||||
account.api_last_updated = datetime.utcnow()
|
||||
account.save()
|
||||
return account
|
||||
|
||||
def import_eve_character(api_key, user_id, character_id):
|
||||
|
||||
@@ -24,13 +24,7 @@ class UpdateAPIs():
|
||||
if not acc.user:
|
||||
acc.delete()
|
||||
continue
|
||||
try:
|
||||
eve_api.api_puller.accounts.import_eve_account(acc.api_key, acc.api_user_id)
|
||||
acc.api_status = 1
|
||||
except APIAuthException:
|
||||
acc.api_status = 2
|
||||
|
||||
acc.save()
|
||||
|
||||
if self.settings['update_corp']:
|
||||
for corp in EVEPlayerCorporation.objects.all():
|
||||
|
||||
Reference in New Issue
Block a user