-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
4,364 additions
and
8 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
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,22 @@ | ||
VERSION = (1, 0, 0, 'final', 0) | ||
|
||
|
||
def get_version(): | ||
"Returns a PEP 386-compliant version number from VERSION." | ||
assert len(VERSION) == 5 | ||
assert VERSION[3] in ('alpha', 'beta', 'rc', 'final') | ||
|
||
# Now build the two parts of the version number: | ||
# main = X.Y[.Z] | ||
# sub = .devN - for pre-alpha releases | ||
# | {a|b|c}N - for alpha, beta and rc releases | ||
|
||
parts = 2 if VERSION[2] == 0 else 3 | ||
main = '.'.join(str(x) for x in VERSION[:parts]) | ||
|
||
sub = '' | ||
if VERSION[3] != 'final': | ||
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} | ||
sub = mapping[VERSION[3]] + str(VERSION[4]) | ||
|
||
return str(main + sub) |
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,46 @@ | ||
from django.contrib import admin | ||
from django.contrib.sites.models import RequestSite | ||
from django.contrib.sites.models import Site | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from registration.models import RegistrationProfile | ||
|
||
|
||
class RegistrationAdmin(admin.ModelAdmin): | ||
actions = ['activate_users', 'resend_activation_email'] | ||
list_display = ('user', 'activation_key_expired') | ||
raw_id_fields = ['user'] | ||
search_fields = ('user__username', 'user__first_name', 'user__last_name') | ||
|
||
def activate_users(self, request, queryset): | ||
""" | ||
Activates the selected users, if they are not alrady | ||
activated. | ||
""" | ||
for profile in queryset: | ||
RegistrationProfile.objects.activate_user(profile.activation_key) | ||
activate_users.short_description = _("Activate users") | ||
|
||
def resend_activation_email(self, request, queryset): | ||
""" | ||
Re-sends activation emails for the selected users. | ||
Note that this will *only* send activation emails for users | ||
who are eligible to activate; emails will not be sent to users | ||
whose activation keys have expired or who have already | ||
activated. | ||
""" | ||
if Site._meta.installed: | ||
site = Site.objects.get_current() | ||
else: | ||
site = RequestSite(request) | ||
|
||
for profile in queryset: | ||
if not profile.activation_key_expired(): | ||
profile.send_activation_email(site) | ||
resend_activation_email.short_description = _("Re-send activation emails") | ||
|
||
|
||
admin.site.register(RegistrationProfile, RegistrationAdmin) |
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,60 @@ | ||
""" | ||
URL patterns for the views included in ``django.contrib.auth``. | ||
Including these URLs (via the ``include()`` directive) will set up the | ||
following patterns based at whatever URL prefix they are included | ||
under: | ||
* User login at ``login/``. | ||
* User logout at ``logout/``. | ||
* The two-step password change at ``password/change/`` and | ||
``password/change/done/``. | ||
* The four-step password reset at ``password/reset/``, | ||
``password/reset/confirm/``, ``password/reset/complete/`` and | ||
``password/reset/done/``. | ||
The default registration backend already has an ``include()`` for | ||
these URLs, so under the default setup it is not necessary to manually | ||
include these views. Other backends may or may not include them; | ||
consult a specific backend's documentation for details. | ||
""" | ||
|
||
from django.conf.urls import include | ||
from django.conf.urls import patterns | ||
from django.conf.urls import url | ||
|
||
from django.contrib.auth import views as auth_views | ||
|
||
|
||
urlpatterns = patterns('', | ||
url(r'^login/$', | ||
auth_views.login, | ||
{'template_name': 'registration/login.html'}, | ||
name='auth_login'), | ||
url(r'^logout/$', | ||
auth_views.logout, | ||
{'next_page': '/'}, | ||
name='auth_logout'), | ||
url(r'^password/change/$', | ||
auth_views.password_change, | ||
name='auth_password_change'), | ||
url(r'^password/change/done/$', | ||
auth_views.password_change_done, | ||
name='auth_password_change_done'), | ||
url(r'^password/reset/$', | ||
auth_views.password_reset, | ||
name='auth_password_reset'), | ||
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', | ||
auth_views.password_reset_confirm, | ||
name='auth_password_reset_confirm'), | ||
url(r'^password/reset/complete/$', | ||
auth_views.password_reset_complete, | ||
name='auth_password_reset_complete'), | ||
url(r'^password/reset/done/$', | ||
auth_views.password_reset_done, | ||
name='auth_password_reset_done'), | ||
) |
Empty file.
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,50 @@ | ||
""" | ||
URLconf for registration and activation, using django-registration's | ||
default backend. | ||
If the default behavior of these views is acceptable to you, simply | ||
use a line like this in your root URLconf to set up the default URLs | ||
for registration:: | ||
(r'^accounts/', include('registration.backends.default.urls')), | ||
This will also automatically set up the views in | ||
``django.contrib.auth`` at sensible default locations. | ||
If you'd like to customize registration behavior, feel free to set up | ||
your own URL patterns for these views instead. | ||
""" | ||
|
||
|
||
from django.conf.urls import patterns | ||
from django.conf.urls import include | ||
from django.conf.urls import url | ||
from django.views.generic.base import TemplateView | ||
|
||
from registration.backends.default.views import ActivationView | ||
from registration.backends.default.views import RegistrationView | ||
|
||
|
||
urlpatterns = patterns('', | ||
url(r'^activate/complete/$', | ||
TemplateView.as_view(template_name='registration/activation_complete.html'), | ||
name='registration_activation_complete'), | ||
# Activation keys get matched by \w+ instead of the more specific | ||
# [a-fA-F0-9]{40} because a bad activation key should still get to the view; | ||
# that way it can return a sensible "invalid key" message instead of a | ||
# confusing 404. | ||
url(r'^activate/(?P<activation_key>\w+)/$', | ||
ActivationView.as_view(), | ||
name='registration_activate'), | ||
url(r'^register/$', | ||
RegistrationView.as_view(), | ||
name='registration_register'), | ||
url(r'^register/complete/$', | ||
TemplateView.as_view(template_name='registration/registration_complete.html'), | ||
name='registration_complete'), | ||
url(r'^register/closed/$', | ||
TemplateView.as_view(template_name='registration/registration_closed.html'), | ||
name='registration_disallowed'), | ||
(r'', include('registration.auth_urls')), | ||
) |
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,130 @@ | ||
from django.conf import settings | ||
from django.contrib.sites.models import RequestSite | ||
from django.contrib.sites.models import Site | ||
|
||
from registration import signals | ||
from registration.models import RegistrationProfile | ||
from registration.views import ActivationView as BaseActivationView | ||
from registration.views import RegistrationView as BaseRegistrationView | ||
|
||
|
||
class RegistrationView(BaseRegistrationView): | ||
""" | ||
A registration backend which follows a simple workflow: | ||
1. User signs up, inactive account is created. | ||
2. Email is sent to user with activation link. | ||
3. User clicks activation link, account is now active. | ||
Using this backend requires that | ||
* ``registration`` be listed in the ``INSTALLED_APPS`` setting | ||
(since this backend makes use of models defined in this | ||
application). | ||
* The setting ``ACCOUNT_ACTIVATION_DAYS`` be supplied, specifying | ||
(as an integer) the number of days from registration during | ||
which a user may activate their account (after that period | ||
expires, activation will be disallowed). | ||
* The creation of the templates | ||
``registration/activation_email_subject.txt`` and | ||
``registration/activation_email.txt``, which will be used for | ||
the activation email. See the notes for this backends | ||
``register`` method for details regarding these templates. | ||
Additionally, registration can be temporarily closed by adding the | ||
setting ``REGISTRATION_OPEN`` and setting it to | ||
``False``. Omitting this setting, or setting it to ``True``, will | ||
be interpreted as meaning that registration is currently open and | ||
permitted. | ||
Internally, this is accomplished via storing an activation key in | ||
an instance of ``registration.models.RegistrationProfile``. See | ||
that model and its custom manager for full documentation of its | ||
fields and supported operations. | ||
""" | ||
def register(self, request, **cleaned_data): | ||
""" | ||
Given a username, email address and password, register a new | ||
user account, which will initially be inactive. | ||
Along with the new ``User`` object, a new | ||
``registration.models.RegistrationProfile`` will be created, | ||
tied to that ``User``, containing the activation key which | ||
will be used for this account. | ||
An email will be sent to the supplied email address; this | ||
email should contain an activation link. The email will be | ||
rendered using two templates. See the documentation for | ||
``RegistrationProfile.send_activation_email()`` for | ||
information about these templates and the contexts provided to | ||
them. | ||
After the ``User`` and ``RegistrationProfile`` are created and | ||
the activation email is sent, the signal | ||
``registration.signals.user_registered`` will be sent, with | ||
the new ``User`` as the keyword argument ``user`` and the | ||
class of this backend as the sender. | ||
""" | ||
username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'] | ||
if Site._meta.installed: | ||
site = Site.objects.get_current() | ||
else: | ||
site = RequestSite(request) | ||
new_user = RegistrationProfile.objects.create_inactive_user(username, email, | ||
password, site) | ||
signals.user_registered.send(sender=self.__class__, | ||
user=new_user, | ||
request=request) | ||
return new_user | ||
|
||
def registration_allowed(self, request): | ||
""" | ||
Indicate whether account registration is currently permitted, | ||
based on the value of the setting ``REGISTRATION_OPEN``. This | ||
is determined as follows: | ||
* If ``REGISTRATION_OPEN`` is not specified in settings, or is | ||
set to ``True``, registration is permitted. | ||
* If ``REGISTRATION_OPEN`` is both specified and set to | ||
``False``, registration is not permitted. | ||
""" | ||
return getattr(settings, 'REGISTRATION_OPEN', True) | ||
|
||
def get_success_url(self, request, user): | ||
""" | ||
Return the name of the URL to redirect to after successful | ||
user registration. | ||
""" | ||
return ('registration_complete', (), {}) | ||
|
||
|
||
class ActivationView(BaseActivationView): | ||
def activate(self, request, activation_key): | ||
""" | ||
Given an an activation key, look up and activate the user | ||
account corresponding to that key (if possible). | ||
After successful activation, the signal | ||
``registration.signals.user_activated`` will be sent, with the | ||
newly activated ``User`` as the keyword argument ``user`` and | ||
the class of this backend as the sender. | ||
""" | ||
activated_user = RegistrationProfile.objects.activate_user(activation_key) | ||
if activated_user: | ||
signals.user_activated.send(sender=self.__class__, | ||
user=activated_user, | ||
request=request) | ||
return activated_user | ||
|
||
def get_success_url(self, request, user): | ||
return ('registration_activation_complete', (), {}) |
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,36 @@ | ||
""" | ||
URLconf for registration and activation, using django-registration's | ||
one-step backend. | ||
If the default behavior of these views is acceptable to you, simply | ||
use a line like this in your root URLconf to set up the default URLs | ||
for registration:: | ||
(r'^accounts/', include('registration.backends.simple.urls')), | ||
This will also automatically set up the views in | ||
``django.contrib.auth`` at sensible default locations. | ||
If you'd like to customize registration behavior, feel free to set up | ||
your own URL patterns for these views instead. | ||
""" | ||
|
||
|
||
from django.conf.urls import include | ||
from django.conf.urls import patterns | ||
from django.conf.urls import url | ||
from django.views.generic.base import TemplateView | ||
|
||
from registration.backends.simple.views import RegistrationView | ||
|
||
|
||
urlpatterns = patterns('', | ||
url(r'^register/$', | ||
RegistrationView.as_view(), | ||
name='registration_register'), | ||
url(r'^register/closed/$', | ||
TemplateView.as_view(template_name='registration/registration_closed.html'), | ||
name='registration_disallowed'), | ||
(r'', include('registration.auth_urls')), | ||
) |
Oops, something went wrong.