Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
KawowyDzienniczek
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafal
KawowyDzienniczek
Commits
c567c1d8
Commit
c567c1d8
authored
Jul 01, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user & token login
parent
9ddd32d6
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
132 additions
and
3 deletions
+132
-3
__init__.py
KawowyDzienniczek/App/user/__init__.py
+0
-0
admin.py
KawowyDzienniczek/App/user/admin.py
+3
-0
apps.py
KawowyDzienniczek/App/user/apps.py
+5
-0
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+11
-0
init_users.py
KawowyDzienniczek/App/user/management/commands/init_users.py
+21
-0
models.py
KawowyDzienniczek/App/user/models.py
+16
-0
serializers.py
KawowyDzienniczek/App/user/serializers.py
+8
-0
tests.py
KawowyDzienniczek/App/user/tests.py
+3
-0
views.py
KawowyDzienniczek/App/user/views.py
+25
-0
settings.py
KawowyDzienniczek/KawowyDzienniczek/settings.py
+19
-1
urls.py
KawowyDzienniczek/KawowyDzienniczek/urls.py
+18
-2
requirements.txt
requirements.txt
+3
-0
No files found.
KawowyDzienniczek/App/user/__init__.py
0 → 100644
View file @
c567c1d8
KawowyDzienniczek/App/user/admin.py
0 → 100644
View file @
c567c1d8
from
django.contrib
import
admin
# Register your models here.
KawowyDzienniczek/App/user/apps.py
0 → 100644
View file @
c567c1d8
from
django.apps
import
AppConfig
class
UserConfig
(
AppConfig
):
name
=
'user'
KawowyDzienniczek/App/user/management/commands/init.py
0 → 100644
View file @
c567c1d8
from
django.contrib.auth.models
import
User
from
django.core.management
import
call_command
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
,
CommandError
class
Command
(
BaseCommand
):
help
=
''
def
handle
(
self
,
*
args
,
**
options
):
call_command
(
'init_users'
)
KawowyDzienniczek/App/user/management/commands/init_users.py
0 → 100644
View file @
c567c1d8
from
django.contrib.auth.models
import
User
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
,
CommandError
class
Command
(
BaseCommand
):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
users
=
[
[
'admin'
,
'admin'
,
'admin@gmail.com'
,
],
[
'Antek'
,
'Antek'
,
'antek@gmail.com'
],
[
'Rafal'
,
'Rafal'
,
'rafal@gmail.com'
],
[
'Klaudia'
,
'Klaudia'
,
'klaudia@gmail.com'
]
]
print
(
"Creating Users"
)
for
user
in
users
:
print
(
'Create {0}'
.
format
(
user
[
0
]))
new_user
=
User
.
objects
.
create
(
username
=
user
[
0
],
password
=
user
[
1
],
email
=
user
[
2
],
is_active
=
True
,
is_superuser
=
True
,
is_staff
=
True
,)
new_user
.
set_password
(
user
[
1
])
new_user
.
save
()
\ No newline at end of file
KawowyDzienniczek/App/user/models.py
0 → 100644
View file @
c567c1d8
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
rest_framework.authtoken.models
import
Token
# Create your models here.
@
receiver
(
post_save
,
sender
=
User
)
def
create_auth_token
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
:
Token
.
objects
.
create
(
user
=
instance
)
class
UserProfile
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_profile'
,
blank
=
False
,
null
=
False
,
default
=
None
)
KawowyDzienniczek/App/user/serializers.py
0 → 100644
View file @
c567c1d8
from
django.contrib.auth.models
import
User
from
rest_framework
import
serializers
class
UserSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
User
fields
=
(
'url'
,
'id'
,
'username'
,
'email'
)
\ No newline at end of file
KawowyDzienniczek/App/user/tests.py
0 → 100644
View file @
c567c1d8
from
django.test
import
TestCase
# Create your tests here.
KawowyDzienniczek/App/user/views.py
0 → 100644
View file @
c567c1d8
import
rest_framework
from
django.contrib.auth.models
import
User
from
django.shortcuts
import
render
# Create your views here.
from
rest_framework
import
viewsets
from
rest_framework.decorators
import
list_route
from
rest_framework.response
import
Response
from
rest_framework
import
viewsets
,
permissions
from
App.user.serializers
import
UserSerializer
class
UserViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
@
list_route
(
methods
=
[
'get'
])
def
me
(
self
,
request
,
pk
=
None
):
user
=
User
.
objects
.
filter
(
pk
=
request
.
user
.
id
)[
0
]
user_data
=
UserSerializer
(
user
,
context
=
{
'request'
:
request
})
.
data
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
,
data
=
user_data
)
\ No newline at end of file
KawowyDzienniczek/KawowyDzienniczek/settings.py
View file @
c567c1d8
...
@@ -13,7 +13,8 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
...
@@ -13,7 +13,8 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
import
os
import
os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
MEDIA_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
'media'
)
# Quick-start development settings - unsuitable for production
# Quick-start development settings - unsuitable for production
...
@@ -37,8 +38,23 @@ INSTALLED_APPS = [
...
@@ -37,8 +38,23 @@ INSTALLED_APPS = [
'django.contrib.sessions'
,
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'django.contrib.staticfiles'
,
'rest_framework'
,
'rest_framework.authtoken'
,
'App.user'
]
]
REST_FRAMEWORK
=
{
'DEFAULT_PERMISSION_CLASSES'
:
(
'rest_framework.permissions.IsAuthenticated'
,),
'DEFAULT_FILTER_BACKENDS'
:
(
'rest_framework.filters.DjangoFilterBackend'
,),
'DEFAULT_AUTHENTICATION_CLASSES'
:
(
'rest_framework.authentication.SessionAuthentication'
,
'rest_framework.authentication.TokenAuthentication'
,
),
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.LimitOffsetPagination'
,
'PAGE_SIZE'
:
10
}
MIDDLEWARE_CLASSES
=
[
MIDDLEWARE_CLASSES
=
[
'django.middleware.security.SecurityMiddleware'
,
'django.middleware.security.SecurityMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
...
@@ -119,3 +135,5 @@ USE_TZ = True
...
@@ -119,3 +135,5 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.9/howto/static-files/
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL
=
'/static/'
STATIC_URL
=
'/static/'
MEDIA_URL
=
'/media/'
KawowyDzienniczek/KawowyDzienniczek/urls.py
View file @
c567c1d8
...
@@ -13,9 +13,25 @@ Including another URLconf
...
@@ -13,9 +13,25 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
"""
from
django.conf.urls
import
url
from
django.conf.urls
import
url
,
include
from
django.conf.urls.static
import
static
from
django.contrib
import
admin
from
django.contrib
import
admin
from
rest_framework
import
routers
from
App.user
import
views
as
user_views
from
rest_framework.authtoken
import
views
as
token_view
from
KawowyDzienniczek
import
settings
from
App.user
import
views
as
user_views
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'user'
,
user_views
.
UserViewSet
)
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^api/'
,
include
(
router
.
urls
)),
url
(
r'^admin/'
,
admin
.
site
.
urls
),
url
(
r'^admin/'
,
admin
.
site
.
urls
),
]
url
(
r'^api-auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
)),
url
(
r'^api-token-auth/'
,
token_view
.
obtain_auth_token
),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
]
+
static
(
settings
.
MEDIA_URL
,
document_root
=
settings
.
MEDIA_ROOT
)
requirements.txt
View file @
c567c1d8
django-filter
django
djangorestframework
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment