The user should be able to get his api key

This commit is contained in:
nikolark committed 2013-10-27 21:22:03 +01:00
1 parent 3b2cfcc2c2
commit 9a017217af
3 files changed
+21 -2

No files matched your search

+1 -1
View File
@@ -44,7 +44,7 @@ Download latest version of Vagrant from [downloads.vagrantup.com](http://downloa
## Design References
A similar data model might allready [exist](http://www.databaseanswers.org/data_models/generic_foundation/index.htm) [out](http://www.databaseanswers.org/data_models/organisations_and_people_and_transactions/index.htm) [there](http://www.databaseanswers.org/data_models/organisations_and_people/index.htm).
A similar data model might allready [exist](http://www.databaseanswers.org/data_models/generic_foundation/index.htm) [out](http://www.databaseanswers.org/data_models/organisations_and_people_and_transactions/index.htm) [there](http://www.databaseanswers.org/data_models/organisations_and_people/index.htm), [somewhere](http://www.databaseanswers.org/data_models/magazine_subscriptions/index.htm).
## Developer References
+1
View File
@@ -18,4 +18,5 @@ v1_api.register(InstitutionResource())
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(v1_api.urls)),
url(r'^authenticate/', 'dusken.views.authenticate')
)
+19 -1
View File
@@ -1 +1,19 @@
# Create your views here.
import json
from django.contrib.auth.forms import AuthenticationForm
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def authenticate(request):
# TODO is this right?
if request.method == "POST":
form = AuthenticationForm(data=request.POST)
if form.is_valid():
# get apikey and return it
user = form.get_user()
api_key = user.api_key.key
return HttpResponse(json.dumps({'api_key': api_key}), content_type='application/javascript; charset=utf8')
else:
return HttpResponse(json.dumps({'error': 'unauthorized'}), content_type='application/javascript; charset=utf8', status=401)
else:
return HttpResponse(json.dumps({'error': 'unauthorized'}), content_type='application/javascript; charset=utf8', status=401)