· 9 years ago · Jan 31, 2017, 06:02 AM
1{
2 "detail": "Authentication credentials were not provided."
3}
4
5Django settings for testinf123 project.
6
7Generated by 'django-admin startproject' using Django 1.8.7.
8
9For more information on this file, see
10https://docs.djangoproject.com/en/1.8/topics/settings/
11
12For the full list of settings and their values, see
13https://docs.djangoproject.com/en/1.8/ref/settings/
14"""
15
16# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17import os
18
19BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20
21
22# Quick-start development settings - unsuitable for production
23# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
24
25# SECURITY WARNING: keep the secret key used in production secret!
26SECRET_KEY = '2d#4%o472cbk$kmv=!m@-94hr$zj*sr@4n5-037x^qxo5sg-zn'
27
28# SECURITY WARNING: don't run with debug turned on in production!
29DEBUG = True
30
31ALLOWED_HOSTS = []
32
33
34# Application definition
35
36INSTALLED_APPS = (
37 'django.contrib.admin',
38 'django.contrib.auth',
39 'django.contrib.contenttypes',
40 'django.contrib.sessions',
41 'django.contrib.messages',
42 'django.contrib.staticfiles',
43 'tester123',
44 'rest_framework',
45 'oauth2_provider',
46 'corsheaders'
47)
48
49MIDDLEWARE_CLASSES = (
50 'django.contrib.sessions.middleware.SessionMiddleware',
51 'django.middleware.common.CommonMiddleware',
52 'django.contrib.auth.middleware.AuthenticationMiddleware',
53 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
54 'django.contrib.messages.middleware.MessageMiddleware',
55 'django.middleware.clickjacking.XFrameOptionsMiddleware',
56 'django.middleware.security.SecurityMiddleware',
57 'corsheaders.middleware.CorsMiddleware',
58)
59
60ROOT_URLCONF = 'testinf123.urls'
61
62
63CORS_ORIGIN_ALLOW_ALL = True
64
65TEMPLATES = [
66 {
67 'BACKEND': 'django.template.backends.django.DjangoTemplates',
68 'DIRS': []
69 ,
70 'APP_DIRS': True,
71 'OPTIONS': {
72 'context_processors': [
73 'django.template.context_processors.debug',
74 'django.template.context_processors.request',
75 'django.contrib.auth.context_processors.auth',
76 'django.contrib.messages.context_processors.messages',
77 ],
78 },
79 },
80]
81
82WSGI_APPLICATION = 'testinf123.wsgi.application'
83
84REST_FRAMEWORK = {
85 'DEFAULT_AUTHENTICATION_CLASSES': (
86 'oauth2_provider.ext.rest_framework.OAuth2Authentication',
87 ),
88 'DEFAULT_PERMISSION_CLASSES': (
89 'rest_framework.permissions.IsAuthenticated',
90 ),
91
92}
93
94
95OAUTH2_PROVIDER = {
96 # this is the list of available scopes
97 'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
98}
99
100# Database
101# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
102
103DATABASES = {
104 'default': {
105 'ENGINE': 'django.db.backends.mysql',
106 'NAME': 'untouched_db',
107 'USER': 'root',
108 'PASSWORD':'root123',
109 'HOST':'localhost',
110 'PORT':'3306'
111 }
112}
113
114
115# Internationalization
116# https://docs.djangoproject.com/en/1.8/topics/i18n/
117
118LANGUAGE_CODE = 'en-us'
119
120TIME_ZONE = 'UTC'
121
122USE_I18N = True
123
124USE_L10N = True
125
126USE_TZ = True
127
128
129# Static files (CSS, JavaScript, Images)
130# https://docs.djangoproject.com/en/1.8/howto/static-files/
131
132STATIC_URL = '/static/'
133
134from rest_framework import routers
135from tester123.views import UserViewSet,GroupViewSet
136from tester123 import views
137from django.conf.urls import url, include
138from django.conf.urls import url, include
139import oauth2_provider.views as oauth2_views
140from django.conf import settings
141from .views import ApiEndpoint
142
143router = routers.DefaultRouter()
144router.register(r'users', UserViewSet)
145router.register(r'groups', GroupViewSet)
146
147
148# OAuth2 provider endpoints
149oauth2_endpoint_views = [
150 url(r'^authorize/$', oauth2_views.AuthorizationView.as_view(), name="authorize"),
151 url(r'^token/$', oauth2_views.TokenView.as_view(), name="token"),
152 url(r'^revoke-token/$', oauth2_views.RevokeTokenView.as_view(), name="revoke-token"),
153]
154
155if settings.DEBUG:
156 # OAuth2 Application Management endpoints
157 oauth2_endpoint_views += [
158 url(r'^applications/$', oauth2_views.ApplicationList.as_view(), name="list"),
159 url(r'^applications/register/$', oauth2_views.ApplicationRegistration.as_view(), name="register"),
160 url(r'^applications/(?P<pk>d+)/$', oauth2_views.ApplicationDetail.as_view(), name="detail"),
161 url(r'^applications/(?P<pk>d+)/delete/$', oauth2_views.ApplicationDelete.as_view(), name="delete"),
162 url(r'^applications/(?P<pk>d+)/update/$', oauth2_views.ApplicationUpdate.as_view(), name="update"),
163 ]
164
165 # OAuth2 Token Management endpoints
166 oauth2_endpoint_views += [
167 url(r'^authorized-tokens/$', oauth2_views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
168 url(r'^authorized-tokens/(?P<pk>d+)/delete/$', oauth2_views.AuthorizedTokenDeleteView.as_view(),
169 name="authorized-token-delete"),
170 ]
171
172urlpatterns = [
173 url(r'^o/', include(oauth2_endpoint_views, namespace="oauth2_provider")),
174 url(r'^api/hello', ApiEndpoint.as_view()), # an example resource endpoint
175 url(r'^user/register', views.register.as_view()), # an example resource endpoint
176 url(r'^', views.OnePageViewApp),
177]
178
179class register(APIView):
180 def post(self, request, format=None):
181 user = User.objects.create_user(request.data['username'],request.data['email'],request.data['password'])
182 user.first_name = request.data['fname']
183 user.last_name= request.data['lname']
184 user.save()
185 return Response({'user':user},status=HTTP_200_OK)