From a7452c1e1473875d28a5500a629b976fa4ce1303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Val=C3=A9rio?= Date: Tue, 31 Mar 2020 18:37:34 +0100 Subject: [PATCH] update documentation --- CONTRIBUTING.rst | 15 ++++++ README.rst | 70 +++++++++++---------------- django_cryptolock/backends.py | 6 +-- django_cryptolock/forms.py | 2 +- django_cryptolock/models.py | 3 -- django_cryptolock/urls.py | 1 - django_cryptolock/views.py | 2 - docs/django_cryptolock.migrations.rst | 8 +++ docs/features_roadmap.rst | 18 +++++++ docs/index.rst | 1 + docs/installation.rst | 2 +- docs/usage.rst | 41 +++++++++++++++- 12 files changed, 113 insertions(+), 56 deletions(-) create mode 100644 docs/features_roadmap.rst diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index be7de5d..14c49ec 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -94,6 +94,21 @@ Ready to contribute? Here's how to set up `django-cryptolock` for local developm 8. Submit a pull request through the GitHub website. + +Running tests for specific environments +--------------------------------------- + +Do want to test only a specific python version / django version locally? + +You can use tox directly:: + +:: + + source /bin/activate + (myenv) $ pip install tox + (myenv) $ tox -e -django-<22_or_30> + + Pull Request Guidelines ----------------------- diff --git a/README.rst b/README.rst index 6f11caa..0985d40 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,13 @@ Django-Cryptolock .. image:: https://coveralls.io/repos/github/dethos/django-cryptolock/badge.svg :target: https://coveralls.io/github/dethos/django-cryptolock -Django authentication using cryptocurrency wallets. +Authenticatio using cryptocurrency wallets for Django projects + +This package provided a django app containing a set of utilities to make easier to +implement the BitId and Monero Cryptolock authentication "protocols". + +Future releases might include other cryptocurrencies but for the being +(until we reach some stability) the focus will continue BTC and XMR. **DISCLAIMER:** This package is still in an early stage of development. It isn't meant to be used on any production scenario yet (in other words, only test projects for now). @@ -24,11 +30,11 @@ The full documentation is at https://django-cryptolock.readthedocs.io. Quickstart ---------- -Install Django-Cryptolock:: +1. Install Django-Cryptolock:: pip install django-cryptolock -Add it to your `INSTALLED_APPS`: +2. Add it to your `INSTALLED_APPS`: .. code-block:: python @@ -38,9 +44,26 @@ Add it to your `INSTALLED_APPS`: ... ) -Migrate your database. +3. Migrate your database:: -Add Django-Cryptolock's URL patterns: + python manage.py migrate + + +4. Add the following settings to your project for the Monero Backend: + +.. code-block:: python + + AUTHENTICATION_BACKENDS = [ + "django_cryptolock.backends.MoneroAddressBackend", + ... + ] + DJCL_MONERO_NETWORK = "mainnet" + DJCL_MONERO_WALLET_RPC_PROTOCOL = "" + DJCL_MONERO_WALLET_RPC_HOST = ":" + DJCL_MONERO_WALLET_RPC_USER = "" + DJCL_MONERO_WALLET_RPC_PASS = "" + +5. Add Django-Cryptolock's URL patterns: .. code-block:: python @@ -53,42 +76,7 @@ Add Django-Cryptolock's URL patterns: ... ] - -Add the following settings to your project for the Monero Backend: - -* ``django_cryptolock.backends.MoneroAddressBackend`` to your - ``AUTHENTICATION_BACKENDS`` -* Set ``DJCL_MONERO_NETWORK`` with the network in use: ``mainnet``, - ``stagenet`` or ``testnet`` -* Use ``DJCL_MONERO_WALLET_RPC_PROTOCOL``, ``DJCL_MONERO_WALLET_RPC_HOST``, - ``DJCL_MONERO_WALLET_RPC_USER`` and ``DJCL_MONERO_WALLET_RPC_PASS`` to specify - which wallet RPC should be used. - -In case only Bitcoin Backend is used, you just need: - -* ``DJCL_BITCOIN_NETWORK`` with -one of two possible values: ``mainnet`` or ``testnet``. -* Add ``django_cryptolock.backends.BitcoinAddressBackend`` to your - ``AUTHENTICATION_BACKENDS`` - -Finaly create the templates files (``login.html`` and ``signup.html``) under a -``django_cryptolock`` subfolder. - -Features --------- - -* Adds authentication based on cryptocurrency wallets to a Django project. - -Running Tests -------------- - -Does the code actually work? - -:: - - source /bin/activate - (myenv) $ pip install tox - (myenv) $ tox -e -django-22 +More detailed information can be found in the documentation. Credits ------- diff --git a/django_cryptolock/backends.py b/django_cryptolock/backends.py index 55a6594..edbea60 100644 --- a/django_cryptolock/backends.py +++ b/django_cryptolock/backends.py @@ -1,16 +1,12 @@ from django.contrib.auth.backends import ModelBackend -from django.contrib.auth import get_user_model from django.core.exceptions import PermissionDenied from django.utils.translation import gettext_lazy as _ -from django.conf import settings -from monerorpc.authproxy import AuthServiceProxy, JSONRPCException +from monerorpc.authproxy import JSONRPCException from .models import Address from .utils import verify_monero_signature, verify_bitcoin_signature -User = get_user_model() - class MoneroAddressBackend(ModelBackend): """Custom Monero-Cryptolock authentication backend.""" diff --git a/django_cryptolock/forms.py b/django_cryptolock/forms.py index 7b4bb71..815fe7c 100644 --- a/django_cryptolock/forms.py +++ b/django_cryptolock/forms.py @@ -2,7 +2,7 @@ from django import forms from django.contrib.auth import authenticate from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError -from django.utils.translation import gettext, gettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.conf import settings from pybitid import bitid diff --git a/django_cryptolock/models.py b/django_cryptolock/models.py index a5f4cf3..6676408 100644 --- a/django_cryptolock/models.py +++ b/django_cryptolock/models.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- - from django.db import models -from django.http.request import HttpRequest from django.conf import settings from django.utils.translation import gettext_lazy as _ from django.core.exceptions import ValidationError @@ -9,7 +7,6 @@ from django.core.exceptions import ValidationError from model_utils.models import TimeStampedModel from .validators import validate_monero_address, validate_bitcoin_address -from .utils import verify_bitcoin_signature, verify_monero_signature class Address(TimeStampedModel): diff --git a/django_cryptolock/urls.py b/django_cryptolock/urls.py index 8e4016e..08eb02f 100644 --- a/django_cryptolock/urls.py +++ b/django_cryptolock/urls.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from django.conf.urls import url -from django.views.generic import TemplateView from .views import CryptoLockLoginView, CryptoLockSignUpView diff --git a/django_cryptolock/views.py b/django_cryptolock/views.py index 2f4c7b7..0b4c461 100644 --- a/django_cryptolock/views.py +++ b/django_cryptolock/views.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ from django.contrib.auth.views import LoginView from django.contrib.auth import get_user_model from django.views.generic import FormView from django.forms.utils import ErrorList from django.conf import settings -from django.urls import reverse from monerorpc.authproxy import JSONRPCException diff --git a/docs/django_cryptolock.migrations.rst b/docs/django_cryptolock.migrations.rst index 4309d4b..ad94b23 100644 --- a/docs/django_cryptolock.migrations.rst +++ b/docs/django_cryptolock.migrations.rst @@ -12,6 +12,14 @@ django\_cryptolock.migrations.0001\_initial module :undoc-members: :show-inheritance: +django\_cryptolock.migrations.0002\_auto\_20200218\_1312 module +--------------------------------------------------------------- + +.. automodule:: django_cryptolock.migrations.0002_auto_20200218_1312 + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/docs/features_roadmap.rst b/docs/features_roadmap.rst new file mode 100644 index 0000000..5e70beb --- /dev/null +++ b/docs/features_roadmap.rst @@ -0,0 +1,18 @@ +==================== +Features and Roadmap +==================== + +Features +-------- + +Below are some of the features the package already supports: + +* Authentication using BitId +* Authentication using Monero-Cryptolock +* Supports custom user models + +Roadmap +------- + +* QR code generation +* Multiple login addresses per-user diff --git a/docs/index.rst b/docs/index.rst index 392af46..5f8a6c4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,6 +14,7 @@ Contents: readme installation usage + features_roadmap contributing authors history diff --git a/docs/installation.rst b/docs/installation.rst index 5f62634..91752fa 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -4,7 +4,7 @@ Installation At the command line:: - $ easy_install django-cryptolock + $ pip install django-cryptolock Or, if you have virtualenvwrapper installed:: diff --git a/docs/usage.rst b/docs/usage.rst index 35eb73b..9883b56 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -12,15 +12,52 @@ To use Django-Cryptolock in a project, add it to your `INSTALLED_APPS`: ... ) +Now you should add the auth backend you wish to use on your project. You can use one or more: + +.. code-block:: python + + AUTHENTICATION_BACKENDS = [ + "django_cryptolock.backends.BitcoinAddressBackend", + "django_cryptolock.backends.MoneroAddressBackend", + ] + +If you use Monero, currently the following extra settings are required: + +.. code-block:: python + + DJCL_MONERO_NETWORK = "mainnet" # mainnet, stagenet or testnet + DJCL_MONERO_WALLET_RPC_PROTOCOL = "" + DJCL_MONERO_WALLET_RPC_HOST = ":" + DJCL_MONERO_WALLET_RPC_USER = "" + DJCL_MONERO_WALLET_RPC_PASS = "" + +For Bitcoin, you only need to set the ``DJCL_BITCOIN_NETWORK``: + +.. code-block:: python + + DJCL_BITCOIN_NETWORK = "mainnet" # mainnet or testnet + Add Django-Cryptolock's URL patterns: .. code-block:: python - from django_cryptolock import urls as django_cryptolock_urls + from django.conf.urls import url urlpatterns = [ ... - url(r'^', include(django_cryptolock_urls)), + url(r"^auth/", include("django_cryptolock.urls", namespace="django_cryptolock")), ... ] + +This will add 2 routes : + +* ``django_cryptolock:signup`` +* ``django_cryptolock:login`` + +For usega within you templates. For specific auth pages you can create the +template files (``login.html`` and ``signup.html``) under a +``django_cryptolock`` subfolder. + +Both of these templates will have access to a ``form```containing the required +fields for the authentication.