From 65f05ea0ef45a42a7dfcc027bfcfd04db786116a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Marti=CC=81n?= Date: Tue, 31 Mar 2015 07:53:16 +0200 Subject: [PATCH] Added basic auth endpoints --- config/requirements.txt | 5 +++++ shelfzilla/settings/base.py | 28 ++++++++++++++++++++++++++++ shelfzilla/urls.py | 11 ++++++++++- shelfzilla/views.py | 11 +++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/config/requirements.txt b/config/requirements.txt index 4a18675..73bf50a 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -25,3 +25,8 @@ django-filer==0.9.8 # Blog django-ckeditor-updated==4.4.4 + +# API +djoser==0.2.1 +djangorestframework==3.1.1 +django-cors-headers==1.0.0 diff --git a/shelfzilla/settings/base.py b/shelfzilla/settings/base.py index 73c01ff..58cdc5a 100644 --- a/shelfzilla/settings/base.py +++ b/shelfzilla/settings/base.py @@ -70,6 +70,12 @@ INSTALLED_APPS = ( 'shelfzilla.apps.manga', 'shelfzilla.apps.blog', 'shelfzilla.apps.pjax', + + # API + 'corsheaders', + 'rest_framework', + 'rest_framework.authtoken', + 'djoser', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -94,6 +100,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( MIDDLEWARE_CLASSES = ( 'reversion.middleware.RevisionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -297,3 +304,24 @@ CKEDITOR_CONFIGS = { # AUTH # AUTH_USER_MODEL = 'account.User' + + +# +# API +# +CORS_ORIGIN_ALLOW_ALL = True + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.TokenAuthentication', + ), +} + +DJOSER = { + 'DOMAIN': 'shelfzilla.com', + 'SITE_NAME': 'Shelfzilla', + 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', + 'ACTIVATION_URL': '#/activate/{uid}/{token}', + 'LOGIN_AFTER_ACTIVATION': True, + 'SEND_ACTIVATION_EMAIL': False, +} diff --git a/shelfzilla/urls.py b/shelfzilla/urls.py index 06e02b2..c4ec46f 100644 --- a/shelfzilla/urls.py +++ b/shelfzilla/urls.py @@ -2,7 +2,7 @@ from django.conf.urls import patterns, include, url from django.conf import settings from django.contrib import admin -from .views import MessagesView +from .views import MessagesView, BlockedView admin.autodiscover() @@ -21,6 +21,15 @@ urlpatterns = patterns( url(r'^search/', include('shelfzilla.apps.manga.urls.search')), url(r'^_admin/', include('shelfzilla.apps._admin.urls')), url(r'^admin/', include(admin.site.urls)), + # url(r'^feedback/', + # include('object_feedback.urls', namespace="object_feedback")), +) + +# API +urlpatterns += patterns( + '', + url(r'^api/v1/auth/register/', BlockedView.as_view()), + url(r'^api/v1/auth/', include('djoser.urls', namespace='api')), ) if settings.DEBUG: diff --git a/shelfzilla/views.py b/shelfzilla/views.py index 0349111..bfe032a 100644 --- a/shelfzilla/views.py +++ b/shelfzilla/views.py @@ -1,9 +1,15 @@ +# coding: utf-8 + +# python import json + +# django from django.views.generic import View as DjangoView from django.template import RequestContext from django.shortcuts import render_to_response from django.http import HttpResponse from django.contrib import messages +from django.core.exceptions import PermissionDenied class View(DjangoView): @@ -46,3 +52,8 @@ class MessagesView(View): ) return result + + +class BlockedView(View): + def dispatch(self, *args, **kwargs): + raise PermissionDenied