Add caminus username validation api

This commit is contained in:
Trever Fischer
2012-02-19 17:44:09 -05:00
parent 6c980fa047
commit ed0a884292
5 changed files with 23 additions and 20 deletions

14
api/handlers.py Normal file
View 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

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -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
View 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)
)

View File

@@ -1 +0,0 @@
# Create your views here.