Redirect to login when attempting to resignup with a used email address.

(imported from commit d58a5dda9a0af409a6ee57cfcd30be45020352d2)
This commit is contained in:
Luke Faraone 2012-09-28 18:49:34 -04:00
parent 50dfbf7a1b
commit aca5cef3eb
3 changed files with 37 additions and 5 deletions

View File

@ -14,6 +14,9 @@ urlpatterns = patterns('',
url(r'^zephyr/', 'zephyr.views.zephyr', name='zephyr'),
url(r'^forge_zephyr/', 'zephyr.views.forge_zephyr', name='forge_zephyr'),
url(r'^accounts/home/', 'zephyr.views.accounts_home', name='accounts_home'),
# We have two entries for accounts/login to allow reverses on the Django
# view we're wrapping to continue to function.
url(r'^accounts/login/', 'zephyr.views.login_page', {'template_name': 'zephyr/login.html'}),
url(r'^accounts/login/', 'django.contrib.auth.views.login', {'template_name': 'zephyr/login.html'}),
url(r'^accounts/logout/', 'django.contrib.auth.views.logout', {'template_name': 'zephyr/index.html'}),
url(r'^accounts/register/', 'zephyr.views.register', name='register'),

View File

@ -4,6 +4,9 @@
<script type="text/javascript">
autofocus('#id_username');
{% if email %}
autofocus('#id_password');
{% endif %}
</script>
<h3>You look familiar.</h3>
@ -14,6 +17,12 @@ autofocus('#id_username');
</div>
{% endif %}
{% if email %}
<div class="alert">
You've already registered with this email address. Please log in below.
</div>
{% endif %}
<input type="hidden" name="next" value="{{ next }}" />
</form>
@ -22,7 +31,7 @@ autofocus('#id_username');
<div class="control-group">
<label for="id_username" class="control-label">Email</label>
<div class="controls">
{{ form.username }}
<input id="id_username" type="text" name="username" value="{{ email }}" maxlength="30" />
</div>
</div>
<div class="control-group">

View File

@ -7,13 +7,14 @@ from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from django.utils.timezone import utc
from django.core.exceptions import ValidationError
from django.contrib.auth.views import login as django_login_page
from django.contrib.auth.models import User
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
Recipient, get_display_recipient, get_huddle, Realm, UserMessage, \
create_user, do_send_zephyr, mit_sync_table, create_user_if_needed, \
create_class_if_needed, PreregistrationUser
from zephyr.forms import RegistrationForm, HomepageForm
from zephyr.forms import RegistrationForm, HomepageForm, is_unique
from zephyr.decorator import asynchronous
from zephyr.lib.query import last_n
@ -58,6 +59,11 @@ def register(request):
email = Confirmation.objects.get(confirmation_key=key).content_object.email
company_name = email.split('@')[-1]
try:
is_unique(email)
except ValidationError:
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' + strip_html(email))
try:
dummy = request.POST['from_confirmation']
form = RegistrationForm()
@ -83,18 +89,32 @@ def register(request):
'form': form, 'company_name': company_name, 'email': email, 'key': key,
})
def login_page(request, **kwargs):
template_response = django_login_page(request, **kwargs)
try:
template_response.context_data['email'] = strip_html(request.GET['email'])
except KeyError:
pass
return template_response
def accounts_home(request):
if request.method == 'POST':
form = HomepageForm(request.POST)
if form.is_valid():
try:
user = PreregistrationUser.objects.get(email=strip_html(form.cleaned_data['email']))
email = form.cleaned_data['email']
user = PreregistrationUser.objects.get(email=email)
except PreregistrationUser.DoesNotExist:
user = PreregistrationUser()
user.email = strip_html(form.cleaned_data['email'])
user.email = email
user.save()
Confirmation.objects.send_confirmation(user, user.email)
return HttpResponseRedirect(reverse('send_confirm', kwargs={'email':user.email}))
try:
email = request.POST['email']
is_unique(email)
except ValidationError:
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' + strip_html(email))
return render_to_response('zephyr/accounts_home.html',
context_instance=RequestContext(request))