Add caminus username validation api
This commit is contained in:
14
api/handlers.py
Normal file
14
api/handlers.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from piston.handler import AnonymousBaseHandler
|
||||
from profiles.models import MinecraftProfile
|
||||
|
||||
class WhitelistHandler(AnonymousBaseHandler):
|
||||
allowed_methods = ('GET',)
|
||||
|
||||
def read(self, request, username=None):
|
||||
if username:
|
||||
try:
|
||||
profile = MinecraftProfile.objects.get(mc_username__exact=username)
|
||||
except Exception, e:
|
||||
return False
|
||||
return profile.user.is_active
|
||||
return False
|
@@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
16
api/tests.py
16
api/tests.py
@@ -1,16 +0,0 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
9
api/urls.py
Normal file
9
api/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from piston.resource import Resource
|
||||
import handlers
|
||||
|
||||
whitelistHandler = Resource(handlers.WhitelistHandler)
|
||||
|
||||
urlpatterns = patterns('api',
|
||||
url(r'^validate/(?P<username>.*)$', whitelistHandler)
|
||||
)
|
@@ -1 +0,0 @@
|
||||
# Create your views here.
|
Reference in New Issue
Block a user