Skip to main content

Core library for Nexus django applications that require User accounts

Project description

=============================
Django GenomiX Users
=============================

.. image:: https://badge.fury.io/py/django-genomix-users.svg
:target: https://badge.fury.io/py/django-genomix-users

.. image:: https://travis-ci.org/chopdgd/django-genomix-users.svg?branch=develop
:target: https://travis-ci.org/chopdgd/django-genomix-users

.. image:: https://codecov.io/gh/chopdgd/django-genomix-users/branch/develop/graph/badge.svg
:target: https://codecov.io/gh/chopdgd/django-genomix-users

.. image:: https://pyup.io/repos/github/chopdgd/django-genomix-users/shield.svg
:target: https://pyup.io/repos/github/chopdgd/django-genomix-users/
:alt: Updates

.. image:: https://pyup.io/repos/github/chopdgd/django-genomix-users/python-3-shield.svg
:target: https://pyup.io/repos/github/chopdgd/django-genomix-users/
:alt: Python 3

Core library for Nexus django applications that require User accounts

Documentation
-------------

The full documentation is at https://django-genomix-users.readthedocs.io.

Quickstart
----------

Install Django GenomiX Users::

pip install django-genomix-users

Make the following changes to `INSTALLED_APPS` in `settings.py` file:

.. code-block:: python

INSTALLED_APPS = (
...
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
...
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django_filters',
...
'django_python3_ldap',
...
'genomix_users',
...
)

Add Django GenomiX Users's URL patterns:

.. code-block:: python

from genomix_users import urls as genomix_users_urls


urlpatterns = [
...
url(r'^', include(genomix_users_urls, namespace='users')),
...
]

Make sure `settings.py` file has `TEMPLATES` and `STATIC_URL` set (example below):

.. code-block:: python

TEMPLATES = [
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
os.path.join(ROOT_DIR, 'templates'),
os.path.join(APPS_DIR, 'templates'),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
# Your stuff: custom template context processors go here
],
},
},
]

STATIC_URL = '/static/'

Make sure `settings.py` file has `MIDDLEWARE` set (example below):

.. code-block:: python

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

Optional settings
-----------------

Turn off the creation of associated user profiles in `settings.py`.

.. code-block:: python

CREATE_PROFILE_ON_SAVE = False

Enable authentication to use JSON Web Token in `settings.py`:

.. code-block:: python

REST_USE_JWT = True

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}

Enable LDAP authentication in `settings.py`:

.. code-block:: python

LDAP_AUTH_URL = 'ldap://chop.edu:3268'

LDAP_AUTH_USE_TLS = False

LDAP_AUTH_SEARCH_BASE = 'dc=chop,dc=edu'

LDAP_AUTH_OBJECT_CLASS = 'person'

LDAP_AUTH_USER_LOOKUP_FIELDS = ('username',)

LDAP_AUTH_USER_FIELDS = {
"username": "sAMAccountName",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}

LDAP_AUTH_FORMAT_USERNAME = 'django_python3_ldap.utils.format_username_active_directory'

LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = 'chop-edu'

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_python3_ldap.auth.LDAPBackend',
]

Enable LDAP User group filtering in `settings.py`:

.. code-block:: python

LDAP_AUTH_FORMAT_SEARCH_FILTERS = 'genomix_users.authentication.genomix_search_filters'

LDAP_AUTH_SEARCH_FILTER = 'CN=dgd_nexus_users,ou=DGD Groups,ou=SecurityGroups,ou=Research,ou=Managed By Others,dc=chop,dc=edu'

Sync User Profile with LDAP fields in `settings.py`:

.. note:: If `CREATE_PROFILE_ON_SAVE = False`, LDAP profile will not sync!

.. code-block:: python

LDAP_AUTH_SYNC_USER_RELATIONS = "genomix_users.authentication.sync_genomix_profile"

# User model fields mapped to the LDAP attributes that represent them.
LDAP_AUTH_PROFILE_FIELDS = {
"title": "title",
}

Features
--------

* GenomiX REST API for authentication using `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
* GenomiX LDAP authentication using `django-python3-ldap <https://github.com/etianen/django-python3-ldap>`_

Running Tests
-------------

Does the code actually work?

::

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits
-------

Tools used in rendering this package:

* Cookiecutter_
* `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage




History
-------

0.1.0 (2017-12-03)
++++++++++++++++++

* First release on PyPI.
* Initial models and REST API.

0.2.0 (2017-12-11)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.1.0...v0.2.0>`_

* Added Profile.
* Added ability to sync profile from LDAP.

0.3.0 (2017-01-05)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.2.0...v0.3.0>`_

* Added REST API filters.

0.3.1 (2017-01-12)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.3.0...v0.3.1>`_

* Fixed route names for SimpleRouter

0.4.0 (2017-02-09)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.3.1...v0.4.0>`_

* Updated requirements to latest

0.5.0 (2017-04-07)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.4.0...v0.5.0>`_

* Added support for Django 2.0 and Python 3.6
* Dropped support for Django < 1.11 and Python 2.7, 3.3, 3.4

0.5.1 (2017-04-10)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.5.0...v0.5.1>`_

* Fixed issue with Admin registration. From now on - users can import and use this in their apps

0.5.2 (2017-04-18)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.5.1...v0.5.2>`_

* Updated 3rd party libs


0.5.3 (2018-05-16)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.5.2...v0.5.3>`_

* Updated setup.py to read install_requires from requirements.txt


0.5.4 (2018-08-13)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.5.3...v0.5.4>`_

* Updated 3rd party requirements. Some requirements had changed so it was causing failures

0.5.5 (2018-10-29)
++++++++++++++++++

`Full Changelog <https://github.com/chopdgd/django-genomix-users/compare/v0.5.4...v0.5.5>`_

* Updated 3rd party requirements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-genomix-users-0.5.5.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

django_genomix_users-0.5.5-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-genomix-users-0.5.5.tar.gz.

File metadata

File hashes

Hashes for django-genomix-users-0.5.5.tar.gz
Algorithm Hash digest
SHA256 4e923837045bad145ee461c9f01fef5613bcd2b8d98a58710a397b4da6cc6ccd
MD5 32aad9283ebcdbf9fe99e3dc2fc96ff0
BLAKE2b-256 b23a55b7ca4a183ee79e98d43b5a6c68e65145e46aba379ab01c5f62e4405fa9

See more details on using hashes here.

Provenance

File details

Details for the file django_genomix_users-0.5.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_genomix_users-0.5.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5dcd7ce4748582a0f14e054a5a922b2704f22a35c4efc64a0811757072440e4a
MD5 93777c0b9a8c2659781ec87b6c55bc2d
BLAKE2b-256 20b985d8ae8eada8784ccf55a31a42a990977504381128510b55c1a5217cee07

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page