mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-19 06:28:03 +00:00
Correctly display errors in add_email
This commit is contained in:
@@ -49,17 +49,20 @@ class AddEmailForm(forms.Form):
|
||||
MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT)
|
||||
|
||||
if num_unconfirmed >= max_num_unconfirmed_emails:
|
||||
self.add_error(None, _('Too many unconfirmed mail addresses!'))
|
||||
return False
|
||||
|
||||
# Check whether or not a confirmation email has been
|
||||
# sent by this user already
|
||||
if UnconfirmedEmail.objects.filter(
|
||||
user=user, email=self.cleaned_data['email']).exists():
|
||||
self.add_error('email', _('Address already added, currently unconfirmed'))
|
||||
return False
|
||||
|
||||
# Check whether or not the email is already confirmed by someone
|
||||
if ConfirmedEmail.objects.filter(
|
||||
email=self.cleaned_data['email']).exists():
|
||||
self.add_error('email', _('Address already confirmed (by someone else)'))
|
||||
return False
|
||||
|
||||
unconfirmed = UnconfirmedEmail()
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if form.errors %}
|
||||
{% for error in form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
<strong>{{ error|escape }}</strong>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<h1>{% trans 'Add a new email address' %}</h1>
|
||||
|
||||
<p>{% blocktrans %}Otherwise, type your email address in the box below and we will send you an email with a link to click on in order to verify that you own that email address.{% endblocktrans %}</p>
|
||||
|
||||
@@ -13,6 +13,7 @@ from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.shortcuts import render
|
||||
|
||||
from openid import oidutil
|
||||
from openid.consumer import consumer
|
||||
@@ -92,7 +93,7 @@ class AddEmailView(SuccessMessageMixin, FormView):
|
||||
|
||||
def form_valid(self, form):
|
||||
if not form.save(self.request):
|
||||
messages.error(self.request, _('Address not added'))
|
||||
return render(self.request, self.template_name, { 'form': form })
|
||||
else:
|
||||
messages.success(self.request, _('Address added successfully'))
|
||||
return super().form_valid(form)
|
||||
@@ -369,7 +370,7 @@ class AddOpenIDView(SuccessMessageMixin, FormView):
|
||||
def form_valid(self, form):
|
||||
openid_id = form.save(self.request.user)
|
||||
if not openid_id:
|
||||
messages.error(self.request, _('ID not added'))
|
||||
return render(self.request, self.template_name, { 'form': form })
|
||||
else:
|
||||
messages.success(self.request, _('ID added successfully'))
|
||||
return HttpResponseRedirect(
|
||||
|
||||
Reference in New Issue
Block a user