mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-08 08:06:20 +01:00
Added a check on the api key for duplicate keys
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
from django import forms
|
||||
from services.managers.eve_api_manager import EveApiManager
|
||||
from eveonline.managers import EveManager
|
||||
|
||||
|
||||
class UpdateKeyForm(forms.Form):
|
||||
api_id = forms.CharField(max_length=254, required=True, label="Key ID")
|
||||
api_key = forms.CharField(max_length=254, required=True, label="Verification Code")
|
||||
|
||||
def clean(self):
|
||||
if EveManager.check_if_api_key_pair_exist(self.cleaned_data['api_id']):
|
||||
raise forms.ValidationError(u'API key already exist')
|
||||
|
||||
if not EveApiManager.check_api_is_type_account(self.cleaned_data['api_id'],
|
||||
self.cleaned_data['api_key']):
|
||||
raise forms.ValidationError(u'API not of type account')
|
||||
|
||||
@@ -67,6 +67,13 @@ class EveManager:
|
||||
if EveApiKeyPair.objects.filter(user=user).exists():
|
||||
return EveApiKeyPair.objects.filter(user=user)
|
||||
|
||||
@staticmethod
|
||||
def check_if_api_key_pair_exist(api_id):
|
||||
if EveApiKeyPair.objects.filter(api_id=api_id).exists():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def delete_api_key_pair(api_id, user_id):
|
||||
if EveApiKeyPair.objects.filter(api_id=api_id).exists():
|
||||
|
||||
Reference in New Issue
Block a user