mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Finish moving the eve_api functions out to the eve_api app
This commit is contained in:
33
eve_api/forms.py
Normal file
33
eve_api/forms.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
|
||||
|
||||
|
||||
class EveAPIForm(forms.Form):
|
||||
""" EVE API input form """
|
||||
|
||||
user_id = forms.IntegerField(label=u'User ID')
|
||||
api_key = forms.CharField(label=u'API Key', max_length=64)
|
||||
description = forms.CharField(max_length=100, required=False)
|
||||
|
||||
def clean_api_key(self):
|
||||
|
||||
if not len(self.cleaned_data['api_key']) == 64:
|
||||
raise forms.ValidationError("Provided API Key is not 64 characters long.")
|
||||
|
||||
if re.search(r'[^\.a-zA-Z0-9]', self.cleaned_data['api_key']):
|
||||
raise forms.ValidationError("Provided API Key has invalid characters.")
|
||||
|
||||
def clean_user_id(self):
|
||||
|
||||
if not 'user_id' in self.cleaned_data or self.cleaned_data['user_id'] == '':
|
||||
raise forms.ValidationError("Please provide a valid User ID")
|
||||
|
||||
try:
|
||||
eaccount = EVEAccount.objects.get(api_user_id=self.cleaned_data['user_id'])
|
||||
except EVEAccount.DoesNotExist:
|
||||
return self.cleaned_data
|
||||
else:
|
||||
raise forms.ValidationError("This API User ID is already registered")
|
||||
|
||||
Reference in New Issue
Block a user