Configuration ************* Installing the Backend Authenticator ==================================== You will need to add Django PAM to your ``INSTALLED_APPS``:: INSTALLED_APPS = [ ... 'django_pam', ] Next you will need to add the Django PAM backend to the ``AUTHENTICATION_BACKENDS``:: AUTHENTICATION_BACKENDS = [ 'django_pam.auth.backends.PAMBackend', 'django.contrib.auth.backends.ModelBackend', ] .. note:: 1. The user that runs the application needs to be a member of the ``/etc/shadow`` file group, this is usually the web server user. This is necessary so the web server can authenticate other users. To do this run the command below with the proper user. |br| ``$ sudo usermod -a -G shadow `` 2. If you use your UNIX account username you will be logged in through the ``PAMBackend`` backend. If you use the Django username you will be logged in through the ``ModelBackend``, assuming both usernames and passwords are not the same. Using the Django PAM Login and Logout Templates =============================================== Use as is with Django PAM CSS ----------------------------- Add the statement below to ``urlpatterns`` in your ``urls.py`` file:: re_path(r'^django-pam/', include('django_pam.urls')), Then put the HTML below in your template:: {% load staticfiles %} Login Logout Use Modified CSS ---------------- Add the statements below to ``urlpatterns`` in your ``urls.py`` file:: re_path(r'^login/$', LoginView.as_view(template_name='/login.html'), name='login'), re_path(r"^logout/(?P[\w\-\:/]+)?$", LogoutView.as_view( template_name='/logout.html'), name='logout'), Create ``login.html`` and ``logout.html`` templates. Login:: {% extends "your_base.html" %} {% load staticfiles %} {% block script %} {{ form.media }} {% endblock %} {% block content %}{% include "django_pam/accounts/_login.html" %}{% endblock %} The stanza above includes the Django PAM CSS and JavaScript code through the form. Then your overriding CSS is included. The JavaScript code, that's included from the form, is not dependent on any toolkit. Logout:: {% extends "your_base.html" %} {% load staticfiles %} {% block script %} {% endblock %} {% block content %}{% include "django_pam/accounts/_logout.html" %}{% endblock %} There is no form for logout so the CSS from Django PAM and your overriding CSS need to be included the normal way. Then use something like the HTML below in your HTML template:: {% load staticfiles %} Login Logout Using the Django PAM Login and Logout Modals ============================================ Using the modals require a little more work, but it's still not to difficult. In your ``base.html`` head include:: At the bottom of your ``base.html`` template include this line just before the ```` tag:: {% block modals %}{% endblock %} Then in the template that has your login html add at the bottom of the template:: {% block modals %}
{% include "django_pam/modals/login.html" %} {% include "django_pam/modals/logout.html" %}
{% endblock %} .. note:: The JavaScript for the modals is written in ES6 which is supported in most of the newer browsers. See: `ECMAScript 6 `_. Use `Babel `_ or `Traceur `_ if you wish to `Transpile `_ my JavaScript code.