Skip to content

Commit 0f8392c

Browse files
author
carlos
committed
añadiendo registrarse en maonic
1 parent 18b3073 commit 0f8392c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4201
-0
lines changed

registration/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
VERSION = (0, 8, 0, 'alpha', 1)
2+
3+
def get_version():
4+
version = '%s.%s' % (VERSION[0], VERSION[1])
5+
if VERSION[2]:
6+
version = '%s.%s' % (version, VERSION[2])
7+
if VERSION[3:] == ('alpha', 0):
8+
version = '%s pre-alpha' % version
9+
else:
10+
if VERSION[3] != 'final':
11+
version = "%s %s" % (version, VERSION[3])
12+
if VERSION[4] != 0:
13+
version = '%s %s' % (version, VERSION[4])
14+
return version

registration/admin.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from django.contrib import admin
2+
from django.contrib.sites.models import RequestSite
3+
from django.contrib.sites.models import Site
4+
from django.utils.translation import ugettext_lazy as _
5+
6+
from registration.models import RegistrationProfile
7+
8+
9+
class RegistrationAdmin(admin.ModelAdmin):
10+
actions = ['activate_users', 'resend_activation_email']
11+
list_display = ('user', 'activation_key_expired')
12+
raw_id_fields = ['user']
13+
search_fields = ('user__username', 'user__first_name')
14+
15+
def activate_users(self, request, queryset):
16+
"""
17+
Activates the selected users, if they are not alrady
18+
activated.
19+
20+
"""
21+
for profile in queryset:
22+
RegistrationProfile.objects.activate_user(profile.activation_key)
23+
activate_users.short_description = _("Activate users")
24+
25+
def resend_activation_email(self, request, queryset):
26+
"""
27+
Re-sends activation emails for the selected users.
28+
29+
Note that this will *only* send activation emails for users
30+
who are eligible to activate; emails will not be sent to users
31+
whose activation keys have expired or who have already
32+
activated.
33+
34+
"""
35+
if Site._meta.installed:
36+
site = Site.objects.get_current()
37+
else:
38+
site = RequestSite(request)
39+
40+
for profile in queryset:
41+
if not profile.activation_key_expired():
42+
profile.send_activation_email(site)
43+
resend_activation_email.short_description = _("Re-send activation emails")
44+
45+
46+
admin.site.register(RegistrationProfile, RegistrationAdmin)

registration/auth_urls.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
URL patterns for the views included in ``django.contrib.auth``.
3+
4+
Including these URLs (via the ``include()`` directive) will set up the
5+
following patterns based at whatever URL prefix they are included
6+
under:
7+
8+
* User login at ``login/``.
9+
10+
* User logout at ``logout/``.
11+
12+
* The two-step password change at ``password/change/`` and
13+
``password/change/done/``.
14+
15+
* The four-step password reset at ``password/reset/``,
16+
``password/reset/confirm/``, ``password/reset/complete/`` and
17+
``password/reset/done/``.
18+
19+
The default registration backend already has an ``include()`` for
20+
these URLs, so under the default setup it is not necessary to manually
21+
include these views. Other backends may or may not include them;
22+
consult a specific backend's documentation for details.
23+
24+
"""
25+
26+
from django.conf.urls.defaults import *
27+
28+
from django.contrib.auth import views as auth_views
29+
30+
31+
urlpatterns = patterns('',
32+
url(r'^login/$',
33+
auth_views.login,
34+
{'template_name': 'registration/login.html'},
35+
name='auth_login'),
36+
url(r'^logout/$',
37+
auth_views.logout,
38+
{'template_name': 'registration/logout.html'},
39+
name='auth_logout'),
40+
url(r'^password/change/$',
41+
auth_views.password_change,
42+
name='auth_password_change'),
43+
url(r'^password/change/done/$',
44+
auth_views.password_change_done,
45+
name='auth_password_change_done'),
46+
url(r'^password/reset/$',
47+
auth_views.password_reset,
48+
name='auth_password_reset'),
49+
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
50+
auth_views.password_reset_confirm,
51+
name='auth_password_reset_confirm'),
52+
url(r'^password/reset/complete/$',
53+
auth_views.password_reset_complete,
54+
name='auth_password_reset_complete'),
55+
url(r'^password/reset/done/$',
56+
auth_views.password_reset_done,
57+
name='auth_password_reset_done'),
58+
)

registration/backends/__init__.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.core.exceptions import ImproperlyConfigured
2+
3+
4+
# Python 2.7 has an importlib with import_module; for older Pythons,
5+
# Django's bundled copy provides it.
6+
try:
7+
from importlib import import_module
8+
except ImportError:
9+
from django.utils.importlib import import_module
10+
11+
def get_backend(path):
12+
"""
13+
Return an instance of a registration backend, given the dotted
14+
Python import path (as a string) to the backend class.
15+
16+
If the backend cannot be located (e.g., because no such module
17+
exists, or because the module does not contain a class of the
18+
appropriate name), ``django.core.exceptions.ImproperlyConfigured``
19+
is raised.
20+
21+
"""
22+
i = path.rfind('.')
23+
module, attr = path[:i], path[i+1:]
24+
try:
25+
mod = import_module(module)
26+
except ImportError, e:
27+
raise ImproperlyConfigured('Error loading registration backend %s: "%s"' % (module, e))
28+
try:
29+
backend_class = getattr(mod, attr)
30+
except AttributeError:
31+
raise ImproperlyConfigured('Module "%s" does not define a registration backend named "%s"' % (module, attr))
32+
return backend_class()
+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
from django.conf import settings
2+
from django.contrib.sites.models import RequestSite
3+
from django.contrib.sites.models import Site
4+
5+
from registration import signals
6+
from registration.forms import RegistrationForm
7+
from registration.models import RegistrationProfile
8+
9+
10+
class DefaultBackend(object):
11+
"""
12+
A registration backend which follows a simple workflow:
13+
14+
1. User signs up, inactive account is created.
15+
16+
2. Email is sent to user with activation link.
17+
18+
3. User clicks activation link, account is now active.
19+
20+
Using this backend requires that
21+
22+
* ``registration`` be listed in the ``INSTALLED_APPS`` setting
23+
(since this backend makes use of models defined in this
24+
application).
25+
26+
* The setting ``ACCOUNT_ACTIVATION_DAYS`` be supplied, specifying
27+
(as an integer) the number of days from registration during
28+
which a user may activate their account (after that period
29+
expires, activation will be disallowed).
30+
31+
* The creation of the templates
32+
``registration/activation_email_subject.txt`` and
33+
``registration/activation_email.txt``, which will be used for
34+
the activation email. See the notes for this backends
35+
``register`` method for details regarding these templates.
36+
37+
Additionally, registration can be temporarily closed by adding the
38+
setting ``REGISTRATION_OPEN`` and setting it to
39+
``False``. Omitting this setting, or setting it to ``True``, will
40+
be interpreted as meaning that registration is currently open and
41+
permitted.
42+
43+
Internally, this is accomplished via storing an activation key in
44+
an instance of ``registration.models.RegistrationProfile``. See
45+
that model and its custom manager for full documentation of its
46+
fields and supported operations.
47+
48+
"""
49+
def register(self, request, **kwargs):
50+
"""
51+
Given a username, email address and password, register a new
52+
user account, which will initially be inactive.
53+
54+
Along with the new ``User`` object, a new
55+
``registration.models.RegistrationProfile`` will be created,
56+
tied to that ``User``, containing the activation key which
57+
will be used for this account.
58+
59+
An email will be sent to the supplied email address; this
60+
email should contain an activation link. The email will be
61+
rendered using two templates. See the documentation for
62+
``RegistrationProfile.send_activation_email()`` for
63+
information about these templates and the contexts provided to
64+
them.
65+
66+
After the ``User`` and ``RegistrationProfile`` are created and
67+
the activation email is sent, the signal
68+
``registration.signals.user_registered`` will be sent, with
69+
the new ``User`` as the keyword argument ``user`` and the
70+
class of this backend as the sender.
71+
72+
"""
73+
username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
74+
if Site._meta.installed:
75+
site = Site.objects.get_current()
76+
else:
77+
site = RequestSite(request)
78+
new_user = RegistrationProfile.objects.create_inactive_user(username, email,
79+
password, site)
80+
signals.user_registered.send(sender=self.__class__,
81+
user=new_user,
82+
request=request)
83+
return new_user
84+
85+
def activate(self, request, activation_key):
86+
"""
87+
Given an an activation key, look up and activate the user
88+
account corresponding to that key (if possible).
89+
90+
After successful activation, the signal
91+
``registration.signals.user_activated`` will be sent, with the
92+
newly activated ``User`` as the keyword argument ``user`` and
93+
the class of this backend as the sender.
94+
95+
"""
96+
activated = RegistrationProfile.objects.activate_user(activation_key)
97+
if activated:
98+
signals.user_activated.send(sender=self.__class__,
99+
user=activated,
100+
request=request)
101+
return activated
102+
103+
def registration_allowed(self, request):
104+
"""
105+
Indicate whether account registration is currently permitted,
106+
based on the value of the setting ``REGISTRATION_OPEN``. This
107+
is determined as follows:
108+
109+
* If ``REGISTRATION_OPEN`` is not specified in settings, or is
110+
set to ``True``, registration is permitted.
111+
112+
* If ``REGISTRATION_OPEN`` is both specified and set to
113+
``False``, registration is not permitted.
114+
115+
"""
116+
return getattr(settings, 'REGISTRATION_OPEN', True)
117+
118+
def get_form_class(self, request):
119+
"""
120+
Return the default form class used for user registration.
121+
122+
"""
123+
return RegistrationForm
124+
125+
def post_registration_redirect(self, request, user):
126+
"""
127+
Return the name of the URL to redirect to after successful
128+
user registration.
129+
130+
"""
131+
return ('registration_complete', (), {})
132+
133+
def post_activation_redirect(self, request, user):
134+
"""
135+
Return the name of the URL to redirect to after successful
136+
account activation.
137+
138+
"""
139+
return ('registration_activation_complete', (), {})

registration/backends/default/urls.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
URLconf for registration and activation, using django-registration's
3+
default backend.
4+
5+
If the default behavior of these views is acceptable to you, simply
6+
use a line like this in your root URLconf to set up the default URLs
7+
for registration::
8+
9+
(r'^accounts/', include('registration.backends.default.urls')),
10+
11+
This will also automatically set up the views in
12+
``django.contrib.auth`` at sensible default locations.
13+
14+
If you'd like to customize the behavior (e.g., by passing extra
15+
arguments to the various views) or split up the URLs, feel free to set
16+
up your own URL patterns for these views instead.
17+
18+
"""
19+
20+
21+
from django.conf.urls.defaults import *
22+
from django.views.generic.simple import direct_to_template
23+
24+
from registration.views import activate
25+
from registration.views import register
26+
27+
28+
urlpatterns = patterns('',
29+
url(r'^activate/complete/$',
30+
direct_to_template,
31+
{'template': 'registration/activation_complete.html'},
32+
name='registration_activation_complete'),
33+
# Activation keys get matched by \w+ instead of the more specific
34+
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
35+
# that way it can return a sensible "invalid key" message instead of a
36+
# confusing 404.
37+
url(r'^activate/(?P<activation_key>\w+)/$',
38+
activate,
39+
{'backend': 'registration.backends.default.DefaultBackend'},
40+
name='registration_activate'),
41+
url(r'^register/$',
42+
register,
43+
{'backend': 'registration.backends.default.DefaultBackend'},
44+
name='registration_register'),
45+
url(r'^register/complete/$',
46+
direct_to_template,
47+
{'template': 'registration/registration_complete.html'},
48+
name='registration_complete'),
49+
url(r'^register/closed/$',
50+
direct_to_template,
51+
{'template': 'registration/registration_closed.html'},
52+
name='registration_disallowed'),
53+
(r'', include('registration.auth_urls')),
54+
)

0 commit comments

Comments
 (0)