-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide example project integration (#28)
Demonstrate basic integration of django-improved-user with Django and django-registration.
- Loading branch information
1 parent
db3e06a
commit 791fb68
Showing
28 changed files
with
612 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Project Specific | ||
example_project/db.sqlite3 | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
""" | ||
Django settings for config project. | ||
Generated by 'django-admin startproject' using Django 1.11.3. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.11/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.11/ref/settings/ | ||
""" | ||
|
||
import os | ||
|
||
from django import VERSION as DjangoVersion | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = ')#-l63lltqso!-&dz3r)xb&p#mz*s=dti_l@=1&ynd_3$+sw85' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'improved_user.apps.ImprovedUserConfig', | ||
'user_integration.apps.UserIntegrationConfig', | ||
] | ||
|
||
if DjangoVersion >= (1, 10): | ||
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', | ||
] | ||
else: | ||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
'django.middleware.security.SecurityMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'config.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'config.wsgi.application' | ||
|
||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' | ||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
}, | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators | ||
|
||
AUTH_USER_MODEL = 'improved_user.User' | ||
|
||
LOGIN_REDIRECT_URL = 'home' | ||
LOGIN_URL = LOGOUT_REDIRECT_URL = 'auth_login' | ||
|
||
AUTH_PREFIX = 'django.contrib.auth.password_validation.' | ||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': AUTH_PREFIX + 'UserAttributeSimilarityValidator', | ||
'OPTIONS': { | ||
'user_attributes': ('email', 'full_name', 'short_name'), | ||
}, | ||
}, | ||
{ | ||
'NAME': AUTH_PREFIX + 'MinimumLengthValidator', | ||
'OPTIONS': { | ||
'min_length': 12, | ||
}, | ||
}, | ||
{ | ||
'NAME': AUTH_PREFIX + 'CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': AUTH_PREFIX + 'NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
ACCOUNT_ACTIVATION_DAYS = 3 | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.11/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.11/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""config URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/1.11/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.conf.urls import url, include | ||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) | ||
""" | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
from django.views.generic import TemplateView | ||
|
||
from user_integration import urls as account_urls | ||
|
||
urlpatterns = [ | ||
url(r'^admin/', admin.site.urls), | ||
url(r'^accounts/', include(account_urls)), | ||
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for config project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Script that allows developers to run Django commands""" | ||
import os | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError: | ||
# The above import may fail for some other reason. Ensure that the | ||
# issue is really that Django is missing to avoid masking other | ||
# exceptions on Python 2. | ||
try: | ||
import django # noqa: F401 pylint: disable=unused-import | ||
except ImportError: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
'available on your PYTHONPATH environment variable? Did you ' | ||
'forget to activate a virtual environment?') | ||
raise | ||
execute_from_command_line(sys.argv) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Application Definition File""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class UserIntegrationConfig(AppConfig): | ||
"""AppConfig definition for user integration code""" | ||
name = 'user_integration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Django Improved User Test Project</title> | ||
<meta name="description" content="A test Django project to demo key-features in django-improved-user."> | ||
<meta name="author" content="JamBon Software"> | ||
<!--[if lt IE 9]> | ||
<script src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> | ||
<![endif]--> | ||
</head> | ||
<body> | ||
{% block content %}{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
{% if user.is_authenticated %} | ||
<p>{% blocktrans with name=user.get_short_name %} | ||
Hello {{name}}! | ||
{% endblocktrans %}</p> | ||
<p><a href="{% url 'auth_logout' %}?next={{ request.path }}"> | ||
{% trans 'Log Out' %}</a></p> | ||
{% else %} | ||
<p><a href="{% url 'registration_register' %}"> | ||
{% trans 'Register' %}</a></p> | ||
<p><a href="{% url 'auth_login' %}?next={{ request.path }}"> | ||
{% trans 'Log In' %}</a></p> | ||
{% endif %} | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
example_project/user_integration/templates/registration/activation_complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<p>{% trans 'Your account is now activated.' %}</p> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
example_project/user_integration/templates/registration/activation_email.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% load i18n %} | ||
{% trans "Activate account at" %} {{ site.name }}: | ||
|
||
http://{{ site.domain }}{% url 'registration_activate' activation_key %} | ||
|
||
{% blocktrans %}Link is valid for {{ expiration_days }} days.{% endblocktrans %} |
1 change: 1 addition & 0 deletions
1
example_project/user_integration/templates/registration/activation_email_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% load i18n %}{% trans 'Account activation on' %} {{ site.name }} |
19 changes: 19 additions & 0 deletions
19
example_project/user_integration/templates/registration/login.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<p> | ||
{% trans 'Not a member?' %} | ||
<a href="{% url 'registration_register' %}">{% trans 'Register!' %}</a> | ||
</p> | ||
<form method="post" action="."> | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<p> | ||
{% trans 'Forgot password?' %} | ||
<a href="{% url 'auth_password_reset' %}">{% trans 'Reset it!' %}</a> | ||
</p> | ||
<button type="submit">{% trans 'Log In' %}</button> | ||
</form> | ||
{% endblock %} |
8 changes: 8 additions & 0 deletions
8
example_project/user_integration/templates/registration/logout.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
{# Used only in Django 1.8, as LOGOUT_REDIRECT_URL setting added in 1.10 #} | ||
{# TODO: delete this when Django 1.8 support dropped #} | ||
|
||
{% block content %} | ||
<p>{% trans 'Logged out' %}</p> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
example_project/user_integration/templates/registration/password_reset_done.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<p>{% trans 'Email with password reset instructions has been sent.' %}</p> | ||
{% endblock %} |
5 changes: 5 additions & 0 deletions
5
example_project/user_integration/templates/registration/password_reset_email.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% load i18n %} | ||
{% blocktrans %}Reset password at {{ site_name }}{% endblocktrans %}: | ||
{% block reset_link %} | ||
{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uid token %} | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
example_project/user_integration/templates/registration/registration_complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<p>{% trans 'Your account is now activated.' %}</p> | ||
{% endblock %} |
11 changes: 11 additions & 0 deletions
11
example_project/user_integration/templates/registration/registration_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends parent_template|default:'base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<form method="post" action="{% url 'registration_register' %}"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
|
||
<button type="submit">{% trans 'Register' %}</button> | ||
</form> | ||
{% endblock %} |
Oops, something went wrong.