Enable token-based authentication

master
Tanner Collin 7 years ago
parent 94a8955891
commit 2f74303db8
  1. 65
      caremyway/api/migrations/0005_auto_20170527_2247.py
  2. 29
      caremyway/settings.py
  3. 4
      caremyway/urls.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'),
),
]

@ -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
}

@ -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'))
]

Loading…
Cancel
Save