mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-18 12:19:29 +00:00
Reworking of API key importing, allow keys to be updated
This commit is contained in:
@@ -24,7 +24,9 @@ def eveapi_add(request, post_save_redirect='/'):
|
||||
form = EveAPIForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
||||
task = import_apikey_result.delay(api_key=form.cleaned_data['api_key'], api_userid=form.cleaned_data['user_id'], user=request.user.id)
|
||||
acc = form.save()
|
||||
print acc
|
||||
task = import_apikey_result.delay(api_key=acc.api_key, api_userid=acc.api_user_id, user=request.user.id)
|
||||
try:
|
||||
task.wait(10)
|
||||
except celery.exceptions.TimeoutError:
|
||||
@@ -34,15 +36,53 @@ def eveapi_add(request, post_save_redirect='/'):
|
||||
except:
|
||||
msg = "An unknown error was encountered while trying to add your API key, please try again later."
|
||||
else:
|
||||
msg = "EVE API key %d successfully added." % form.cleaned_data['user_id']
|
||||
msg = "EVE API key %d successfully added." % form.cleaned_data['api_user_id']
|
||||
messages.success(request, msg, fail_silently=True)
|
||||
return redirect(post_save_redirect)
|
||||
else:
|
||||
form = EveAPIForm() # An unbound form
|
||||
form = EveAPIForm(initial={'user': request.user.id }) # An unbound form
|
||||
|
||||
return render_to_response('eve_api/add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def eveapi_update(request, userid, post_save_redirect='/'):
|
||||
""" Update a EVE API Key """
|
||||
|
||||
acc = get_object_or_404(EVEAccount, id=userid)
|
||||
if not acc.user == request.user and not request.user.is_staff:
|
||||
raise Http404
|
||||
|
||||
if request.method == 'POST':
|
||||
form = EveAPIForm(request.POST, instance=acc)
|
||||
if form.is_valid():
|
||||
if form.has_changed() and ('api_key' in form.changed_data or 'api_user_id' in form.changed_data):
|
||||
acc = form.save()
|
||||
task = import_apikey_result.delay(api_key=acc.api_key, api_userid=acc.api_user_id, user=request.user.id)
|
||||
try:
|
||||
task.wait(10)
|
||||
except celery.exceptions.TimeoutError:
|
||||
msg = "The addition of your API key is still processing, please check back in a minute or so."
|
||||
except DocumentRetrievalError:
|
||||
msg = "An issue with the EVE API was encountered while adding your API, please try again later."
|
||||
except:
|
||||
msg = "An unknown error was encountered while trying to add your API key, please try again later."
|
||||
else:
|
||||
msg = "EVE API key %d successfully updated." % acc.api_user_id
|
||||
else:
|
||||
if form.has_changed():
|
||||
form.save()
|
||||
msg = "EVE API key %d successfully updated." % acc.api_user_id
|
||||
|
||||
|
||||
messages.success(request, msg, fail_silently=True)
|
||||
return redirect(post_save_redirect)
|
||||
else:
|
||||
form = EveAPIForm(instance=acc) # An unbound form
|
||||
|
||||
return render_to_response('eve_api/update.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def eveapi_del(request, userid, post_save_redirect='/'):
|
||||
""" Delete a EVE API key from a account """
|
||||
|
||||
Reference in New Issue
Block a user