Commit 0a7cb974 authored by David Seaward's avatar David Seaward

create minimal custom user model that can be registered

parent fc5fcc2e
...@@ -29,6 +29,8 @@ Installation ...@@ -29,6 +29,8 @@ Installation
* Copy `purist_account/settings_local.txt` as `settings_local.py` * Copy `purist_account/settings_local.txt` as `settings_local.py`
* Fill in settings * Fill in settings
* Run `python manage.py migrate --settings=purist_account.settings_local` * Run `python manage.py migrate --settings=purist_account.settings_local`
* Run `python manage.py createsuperuser --settings=purist_account.settings_local`
* When prompted, enter the credentials of your LDAP superuser / account manager
For more options and details see <https://docs.djangoproject.com/en/1.10/#the-development-process> For more options and details see <https://docs.djangoproject.com/en/1.10/#the-development-process>
......
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
# Register your models here. from .models import User
class UserAdmin(BaseUserAdmin):
pass
admin.site.register(User, UserAdmin)
from registration.forms import RegistrationForm as BaseRegistrationForm
from .models import User
class RegistrationForm(BaseRegistrationForm):
class Meta(BaseRegistrationForm.Meta):
model = User
from django.db import models from django.contrib.auth.models import AbstractUser
# Create your models here.
class User(AbstractUser):
pass
...@@ -37,7 +37,6 @@ INSTALLED_APPS = [ ...@@ -37,7 +37,6 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'ldapregister',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -6,6 +6,9 @@ FIXME: switch to storing strict yaml in /etc/ ...@@ -6,6 +6,9 @@ FIXME: switch to storing strict yaml in /etc/
""" """
from .settings import * from .settings import *
from registration_defaults.settings import *
import ldap
from django_auth_ldap.config import LDAPSearch
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'local_secret' SECRET_KEY = 'local_secret'
...@@ -14,8 +17,18 @@ SECRET_KEY = 'local_secret' ...@@ -14,8 +17,18 @@ SECRET_KEY = 'local_secret'
DEBUG = False DEBUG = False
# Required if DEBUG is False # Required if DEBUG is False
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ['example.com']
# INSTALLED_APPS = ["registration_defaults", ] + INSTALLED_APPS + ["ldapregister", ]
INSTALLED_APPS += ["ldapregister", ]
REGISTRATION_OPEN = True
#
# AUTHENTICATION
#
# AUTH_PASSWORD_VALIDATORS = [] # override
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend', 'django_auth_ldap.backend.LDAPBackend',
...@@ -29,6 +42,4 @@ AUTH_LDAP_BIND_DN = "cn=application,dc=example,dc=com" ...@@ -29,6 +42,4 @@ AUTH_LDAP_BIND_DN = "cn=application,dc=example,dc=com"
AUTH_LDAP_BIND_PASSWORD = "password" AUTH_LDAP_BIND_PASSWORD = "password"
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)") AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
# INSTALLED_APPS = ["registration_defaults", ] + INSTALLED_APPS AUTH_USER_MODEL = 'ldapregister.User'
REGISTRATION_OPEN = True
...@@ -15,8 +15,12 @@ Including another URLconf ...@@ -15,8 +15,12 @@ Including another URLconf
""" """
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
from registration.backends.simple.views import RegistrationView
from ldapregister.forms import RegistrationForm
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationForm), name='registration_register'),
url(r'^accounts/', include('registration.backends.simple.urls')), url(r'^accounts/', include('registration.backends.simple.urls')),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment