From 2f74303db8ca9475b4769161ef640c66eaf9e006 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 28 May 2017 03:02:00 +0000 Subject: [PATCH] Enable token-based authentication --- .../api/migrations/0005_auto_20170527_2247.py | 65 +++++++++++++++++++ caremyway/settings.py | 29 +++++++++ caremyway/urls.py | 4 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 caremyway/api/migrations/0005_auto_20170527_2247.py diff --git a/caremyway/api/migrations/0005_auto_20170527_2247.py b/caremyway/api/migrations/0005_auto_20170527_2247.py new file mode 100644 index 0000000..4d8138b --- /dev/null +++ b/caremyway/api/migrations/0005_auto_20170527_2247.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-05-27 22:47 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0004_client_provider'), + ] + + operations = [ + migrations.CreateModel( + name='Manage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('note', models.CharField(blank=True, max_length=500)), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Client')), + ('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Provider')), + ], + ), + migrations.CreateModel( + name='Price', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('amount', models.DecimalField(decimal_places=2, max_digits=8)), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Client')), + ('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Provider')), + ], + ), + migrations.CreateModel( + name='Shift', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('set_start', models.DateTimeField()), + ('set_end', models.DateTimeField()), + ('amount', models.DecimalField(decimal_places=2, max_digits=8)), + ('description', models.CharField(blank=True, max_length=100)), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Client')), + ('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Provider')), + ], + ), + migrations.CreateModel( + name='Work', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('color', models.CharField(blank=True, max_length=16)), + ('label', models.CharField(blank=True, max_length=100)), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Client')), + ], + ), + migrations.AddField( + model_name='shift', + name='work', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Work'), + ), + migrations.AddField( + model_name='price', + name='work', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Work'), + ), + ] diff --git a/caremyway/settings.py b/caremyway/settings.py index 548a3a9..2b8d082 100644 --- a/caremyway/settings.py +++ b/caremyway/settings.py @@ -38,13 +38,42 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'rest_framework.authtoken', 'caremyway.api', + 'rest_auth', + 'django.contrib.sites', + 'allauth', + 'allauth.account', + 'rest_auth.registration', ] +SITE_ID = 1 + +#This is required otherwise it asks for email server +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +ACCOUNT_AUTHENTICATION_METHOD = 'email' +ACCOUNT_EMAIL_REQUIRED = True +ACCOUNT_USERNAME_REQUIRED = False + +#Following is added to enable registration with email instead of username +AUTHENTICATION_BACKENDS = ( + # Needed to login by username in Django admin, regardless of `allauth` + 'django.contrib.auth.backends.ModelBackend', + + # `allauth` specific authentication methods, such as login by e-mail + 'allauth.account.auth_backends.AuthenticationBackend', +) + REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAdminUser', ], + 'DEFAULT_AUTHENTICATION_CLASSES': ( + #'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ), 'PAGE_SIZE': 10 } diff --git a/caremyway/urls.py b/caremyway/urls.py index faff30f..501ad12 100644 --- a/caremyway/urls.py +++ b/caremyway/urls.py @@ -27,5 +27,7 @@ router.register(r'providers', views.ProviderViewSet) # Additionally, we include login URLs for the browsable API. urlpatterns = [ url(r'^', include(router.urls)), - url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), + url(r'^rest-auth/', include('rest_auth.urls')), + url(r'^rest-auth/registration/', include('rest_auth.registration.urls')) ]