Commit 511e9e69 authored by Jasper St. Pierre's avatar Jasper St. Pierre

Use django-registration for email verification

parent 6f4c3a4f
......@@ -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
......@@ -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
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
{% extends "base.html" %}
{% block body %}
Your account is now activated.
{% endblock %}
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
GNOME Shell Extensions - Activate your account
......@@ -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>
......
......@@ -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>
{% extends "base.html" %}
{% block body %}
Thanks! An link for validation should have been sent to your email address!
{% endblock %}
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'),
)
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))
......@@ -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',
......
......@@ -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>
......
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