[extensions-web] Use django-registration for email verification
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Use django-registration for email verification
- Date: Wed, 26 Oct 2011 21:59:27 +0000 (UTC)
commit 511e9e6959a2303e869dcb7359b06f94c703d96f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Oct 26 16:59:17 2011 -0400
Use django-registration for email verification
README.rst | 2 +
requirements.txt | 1 +
sweettooth/auth/forms.py | 26 ++++++++++++-----
.../auth/templates/registration/activate.html | 4 +++
.../templates/registration/activation_email.txt | 9 ++++++
.../registration/activation_email_subject.txt | 1 +
.../registration/activation_email_sujbject.txt | 1 +
.../templates/{auth => registration}/login.html | 1 -
.../{auth => registration}/login_popup_form.html | 2 +-
.../templates/{auth => registration}/profile.html | 0
.../{auth => registration}/profile_edit.html | 0
.../registration/registration_complete.html | 4 +++
.../registration_form.html} | 0
sweettooth/auth/urls.py | 11 +++++--
sweettooth/auth/views.py | 28 +------------------
sweettooth/settings.py | 4 +++
sweettooth/templates/base.html | 2 +-
17 files changed, 56 insertions(+), 40 deletions(-)
---
diff --git a/README.rst b/README.rst
index 745d3ae..111b143 100644
--- a/README.rst
+++ b/README.rst
@@ -86,6 +86,7 @@ Requirements
* Pygments_
* sorl-thumbnail_
* south_
+ * django-registration_
I develop with PostgreSQL_ at home, but Django should be able to use SQLite_,
MySQL_, and others. South_ is used for migrations.
@@ -98,3 +99,4 @@ MySQL_, and others. South_ is used for migrations.
.. _SQLite: http://www.sqlite.org/
.. _MySQL: http://www.mysql.com/
.. _south: http://south.aeracode.org/
+.. _django-registration: http://pypi.python.org/pypi/django-registration
diff --git a/requirements.txt b/requirements.txt
index da6fae5..3ebfbc1 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,6 +2,7 @@ Django==1.2.7
PIL==1.1.7
Pygments==1.4
django-autoslug==1.4.1
+django-registration==0.7
sorl-thumbnail==11.05.2
wsgiref==0.1.2
South==0.7.3
diff --git a/sweettooth/auth/forms.py b/sweettooth/auth/forms.py
index 99dec80..162fea0 100644
--- a/sweettooth/auth/forms.py
+++ b/sweettooth/auth/forms.py
@@ -1,5 +1,8 @@
-from django.contrib.auth import forms, models
+from django.db.models import forms
+from django.contrib.auth import forms as auth_forms
+from django.utils.translation import ugettext_lazy as _
+from registration.forms import RegistrationForm
class PlainOutputForm(object):
def as_plain(self):
@@ -22,16 +25,23 @@ class InlineForm(object):
field.widget.attrs['placeholder'] = field.label
class InlineAuthenticationForm(PlainOutputForm, AutoFocusForm,
- InlineForm, forms.AuthenticationForm):
+ InlineForm, auth_forms.AuthenticationForm):
pass
-class AuthenticationForm(AutoFocusForm, forms.AuthenticationForm):
+class AuthenticationForm(AutoFocusForm, auth_forms.AuthenticationForm):
pass
-class UserCreationEmailForm(forms.UserCreationForm):
- class Meta:
- model = models.User
- fields = 'username', 'email'
+class RegistrationForm(RegistrationForm):
+ # Copies the standard setting from the django.contrib.auth.forms
+ username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w +-]+$',
+ help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
+ error_messages = {'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
+ email = forms.EmailField(widget=forms.TextInput(attrs=dict(maxlength=75)),
+ label=_(u'Email'))
+ password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
+ password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput,
+ help_text = _("Enter the same password as above, for verification."))
-class UserCreationForm(AutoFocusForm, UserCreationEmailForm):
+
+class AutoFocusRegistrationForm(AutoFocusForm, RegistrationForm):
pass
diff --git a/sweettooth/auth/templates/registration/activate.html b/sweettooth/auth/templates/registration/activate.html
new file mode 100644
index 0000000..6f7b4da
--- /dev/null
+++ b/sweettooth/auth/templates/registration/activate.html
@@ -0,0 +1,4 @@
+{% extends "base.html" %}
+{% block body %}
+Your account is now activated.
+{% endblock %}
diff --git a/sweettooth/auth/templates/registration/activation_email.txt b/sweettooth/auth/templates/registration/activation_email.txt
new file mode 100644
index 0000000..a7b3b3f
--- /dev/null
+++ b/sweettooth/auth/templates/registration/activation_email.txt
@@ -0,0 +1,9 @@
+You have registered an account at GNOME Shell Extensions. Please activate
+your account by using the link below:
+
+ https://extensions.gnome.org/accounts/activate/{{ activation_key }}/
+
+You have {{ expiration_days }} remaining to register your account.
+
+Thanks!
+ the GNOME Shell Extensions team
diff --git a/sweettooth/auth/templates/registration/activation_email_subject.txt b/sweettooth/auth/templates/registration/activation_email_subject.txt
new file mode 100644
index 0000000..a9ee09f
--- /dev/null
+++ b/sweettooth/auth/templates/registration/activation_email_subject.txt
@@ -0,0 +1 @@
+GNOME Shell Extensions - Activate your account
diff --git a/sweettooth/auth/templates/registration/activation_email_sujbject.txt b/sweettooth/auth/templates/registration/activation_email_sujbject.txt
new file mode 100644
index 0000000..a9ee09f
--- /dev/null
+++ b/sweettooth/auth/templates/registration/activation_email_sujbject.txt
@@ -0,0 +1 @@
+GNOME Shell Extensions - Activate your account
diff --git a/sweettooth/auth/templates/auth/login.html b/sweettooth/auth/templates/registration/login.html
similarity index 95%
rename from sweettooth/auth/templates/auth/login.html
rename to sweettooth/auth/templates/registration/login.html
index c3b6660..7570033 100644
--- a/sweettooth/auth/templates/auth/login.html
+++ b/sweettooth/auth/templates/registration/login.html
@@ -17,7 +17,6 @@
{% for error in form.password.errors %}
<p class="error">{{ error }}</p>
{% endfor %}
- {{ form.password.errors }}
{{ form.password.label_tag }}
{{ form.password }}
</li>
diff --git a/sweettooth/auth/templates/auth/login_popup_form.html b/sweettooth/auth/templates/registration/login_popup_form.html
similarity index 75%
rename from sweettooth/auth/templates/auth/login_popup_form.html
rename to sweettooth/auth/templates/registration/login_popup_form.html
index 5851198..dcd49e0 100644
--- a/sweettooth/auth/templates/auth/login_popup_form.html
+++ b/sweettooth/auth/templates/registration/login_popup_form.html
@@ -2,5 +2,5 @@
{% csrf_token %}
{{ login_popup_form.as_plain }}
<input type="submit" value="Login">
- <a href="{% url auth-register %}">Register</a>
+ <a href="{% url registration_register %}">Register</a>
</form>
diff --git a/sweettooth/auth/templates/auth/profile.html b/sweettooth/auth/templates/registration/profile.html
similarity index 100%
rename from sweettooth/auth/templates/auth/profile.html
rename to sweettooth/auth/templates/registration/profile.html
diff --git a/sweettooth/auth/templates/auth/profile_edit.html b/sweettooth/auth/templates/registration/profile_edit.html
similarity index 100%
rename from sweettooth/auth/templates/auth/profile_edit.html
rename to sweettooth/auth/templates/registration/profile_edit.html
diff --git a/sweettooth/auth/templates/registration/registration_complete.html b/sweettooth/auth/templates/registration/registration_complete.html
new file mode 100644
index 0000000..15b103c
--- /dev/null
+++ b/sweettooth/auth/templates/registration/registration_complete.html
@@ -0,0 +1,4 @@
+{% extends "base.html" %}
+{% block body %}
+Thanks! An link for validation should have been sent to your email address!
+{% endblock %}
diff --git a/sweettooth/auth/templates/auth/register.html b/sweettooth/auth/templates/registration/registration_form.html
similarity index 100%
rename from sweettooth/auth/templates/auth/register.html
rename to sweettooth/auth/templates/registration/registration_form.html
diff --git a/sweettooth/auth/urls.py b/sweettooth/auth/urls.py
index 8896f43..2d15e73 100644
--- a/sweettooth/auth/urls.py
+++ b/sweettooth/auth/urls.py
@@ -1,16 +1,21 @@
-from django.conf.urls.defaults import patterns, url
+from django.conf.urls.defaults import patterns, url, include
from auth import views, forms
+from registration.views import register
urlpatterns = patterns('',
url(r'^login/', views.login,
- dict(template_name='auth/login.html',
+ dict(template_name='registration/login.html',
authentication_form=forms.AuthenticationForm), name='auth-login'),
url(r'^logout/', views.logout,
dict(next_page='/'), name='auth-logout'),
- url(r'^register/', views.register, name='auth-register'),
+ url(r'^register/$', register,
+ dict(form_class=forms.AutoFocusRegistrationForm),
+ name='registration_register'),
+
+ url(r'', include('registration.urls')),
url(r'^profile/(?P<user>.+)', views.profile, name='auth-profile'),
url(r'^profile/', views.profile_redirect, name='auth-profile'),
)
diff --git a/sweettooth/auth/views.py b/sweettooth/auth/views.py
index e3e3969..5ed0193 100644
--- a/sweettooth/auth/views.py
+++ b/sweettooth/auth/views.py
@@ -1,12 +1,9 @@
from django.contrib.auth import models
-from django.contrib.auth import login as auth_login, authenticate
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import login, logout
from django.shortcuts import get_object_or_404, redirect
-from auth import forms
-
from review.models import CodeReview
from extensions.models import Extension
@@ -15,9 +12,9 @@ from utils import render
def profile(request, user):
userobj = get_object_or_404(models.User, username=user)
- template = 'auth/profile.html'
+ template = 'registration/profile.html'
if request.user == user:
- template = 'auth/profile_edit.html'
+ template = 'registration/profile_edit.html'
display_name = userobj.get_full_name() or userobj.username
extensions = Extension.objects.filter(creator=userobj)
@@ -31,24 +28,3 @@ def profile(request, user):
@login_required
def profile_redirect(request):
return redirect('auth-profile', user=request.user.username)
-
-def register(request):
- if request.method == 'POST':
- form = forms.UserCreationForm(request.POST, request.FILES)
- if form.is_valid():
- user = form.save()
-
- # We want to log the user in after this.
- # The user object that was just returned isn't "authenticated",
- # so a login will fail. The user model doesn't have the real
- # password, but a hash of it, so grab the data from the form.
- authed_user = authenticate(username=form.cleaned_data['username'],
- password=form.cleaned_data['password1'])
- auth_login(request, authed_user)
-
- # Then bounce him to his profile afterwards.
- return redirect('auth-profile', user=user.username)
- else:
- form = forms.UserCreationForm()
-
- return render(request, 'auth/register.html', dict(form=form))
diff --git a/sweettooth/settings.py b/sweettooth/settings.py
index 290db1a..c3fe102 100644
--- a/sweettooth/settings.py
+++ b/sweettooth/settings.py
@@ -109,11 +109,15 @@ TEMPLATE_CONTEXT_PROCESSORS = (
"sweettooth.auth.context_processors.login_form",
)
+ACCOUNT_ACTIVATION_DAYS = 5
+
LOGIN_URL = '/accounts/login/'
INSTALLED_APPS = (
'django.contrib.auth',
+ 'registration',
+
# 'ratings' goes before django's comments
# app so it will find our templates
'ratings',
diff --git a/sweettooth/templates/base.html b/sweettooth/templates/base.html
index b8dca2a..90490e5 100644
--- a/sweettooth/templates/base.html
+++ b/sweettooth/templates/base.html
@@ -41,7 +41,7 @@ window._SW = function() {
</ul>
</div>
{% else %}
- {% include "auth/login_popup_form.html" %}
+ {% include "registration/login_popup_form.html" %}
{% endif %}
</div>
</div>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]