From ca818200acba8ab9de8c814fda8c311b0a76a9cf Mon Sep 17 00:00:00 2001 From: Ruben Grill Date: Sun, 2 Sep 2018 12:12:21 +0200 Subject: [PATCH] docs: Update README --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0c7b231..357cd17 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Run this command to install django-nopassword pip install django-nopassword ### Requirements -Django >= 1.4 (1.5 custom user is supported) +Django >= 1.11 (custom user is supported) ## Usage Add the app to installed apps @@ -22,26 +22,83 @@ INSTALLED_APPS = ( ) ``` -Set the authentication backend to *EmailBackend* +Add the authentication backend *EmailBackend* - AUTHENTICATION_BACKENDS = ('nopassword.backends.email.EmailBackend',) +```python +AUTHENTICATION_BACKENDS = ( + # Needed to login by username in Django admin, regardless of `nopassword` + 'django.contrib.auth.backends.ModelBackend', + + # Send login codes via email + 'nopassword.backends.email.EmailBackend', +) +``` Add urls to your *urls.py* ```python urlpatterns = patterns('', ... - url(r'^accounts/', include('nopassword.urls', namespace='nopassword')), + url(r'^accounts/', include('nopassword.urls')), + ... +) +``` + +### REST API + +To use the REST API, *djangorestframework* must be installed + + pip install djangorestframework + +Add rest framework to installed apps + +```python +INSTALLED_APPS = ( + ... + 'rest_framework', + 'rest_framework.authtoken', + 'nopassword', ... ) ``` +Add *TokenAuthentication* to default authentication classes + +```python +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.TokenAuthentication', + ) +} +``` + +Add urls to your *urls.py* + +```python +urlpatterns = patterns('', + ... + url(r'^api/accounts/', include('nopassword.rest.urls')), + ... +) +``` + +You will have the following endpoints available: + +- `/api/accounts/login/` (POST) + - username + - next (optional, will be returned in `/api/accounts/login/code/` to be handled by the frontend) + - Sends a login code to the user +- `/api/accounts/login/code/` (POST) + - code + - Returns `key` (authentication token) and `next` (provided by `/api/accounts/login/`) +- `/api/accounts/logout/` (POST) + - Performs logout + ### Settings Information about the available settings can be found in the [docs](http://django-nopassword.readthedocs.org/en/latest/#settings) ## Tests Run with `python setup.py test`. -To run with sqlite add `USE_SQLITE = True` in tests/local.py -------- MIT © Rolf Erik Lekang