@@ -32,6 +32,7 @@ class RegistrationForm(forms.Form):
User.objects.get(username__iexact=value)
except User.DoesNotExist:
return self.cleaned_data['username']
+
raise forms.ValidationError(
'This username is already taken. Please choose another.'
)
@@ -39,12 +40,12 @@ class RegistrationForm(forms.Form):
def clean_email(self):
value = self.cleaned_data['email']
try:
- user = User.objects.get(email__iexact=value)
+ User.objects.get(email__iexact=value)
except User.DoesNotExist:
return self.cleaned_data['email']
+
raise forms.ValidationError(
- 'This email address is already in use '
- 'for the account "%s".\n' % user.username
+ 'This email address is already in use for another account.'
)
def clean(self):
@@ -1,113 +1,112 @@
-{% extends "base.html" %}
+{% extends "base2.html" %}
{% block title %}Registration{% endblock %}
-{% block heading %}Registration{% endblock %}
+
+{% block navigation %}{% endblock %}
{% block body %}
-{% if confirmation and not error %}
-<p>
- Registration successful!
-</p>
-<p>
- A confirmation email has been sent to {{ confirmation.email }}.
- You'll need to visit the link provided in that email to confirm your
- registration.
-</p>
-{% else %}
-<p>By creating a Patchwork account, you can:<p>
-<ul>
- <li>create "bundles" of patches</li>
- <li>update the state of your own patches</li>
-</ul>
-<form method="post">
- {% csrf_token %}
- <table class="form registerform">
- <tr>
- <th colspan="2" class="headerrow">register</th>
- </tr>
-{% if error %}
- <tr>
- <td colspan="2">{{ error }}</td>
- </tr>
-{% endif %}
- <tr>
- <td>{{ form.first_name.label_tag }}</td>
- <td>
-{% if form.first_name.errors %}
- {{ form.first_name.errors }}
-{% endif %}
- {{ form.first_name }}
-{% if form.first_name.help_text %}
- <div class="help_text"/>{{ form.first_name.help_text }}</div>
-{% endif %}
- </td>
- </tr>
- <tr>
- <td>{{ form.last_name.label_tag }}</td>
- <td>
-{% if form.last_name.errors %}
- {{ form.last_name.errors }}
-{% endif %}
- {{ form.last_name }}
-{% if form.last_name.help_text %}
- <div class="help_text"/>{{ form.last_name.help_text }}</div>
-{% endif %}
- </td>
- </tr>
- <tr>
- <td></td>
- <td class="form-help">
- Your name is used to identify you on the site
- </td>
- </tr>
- <tr>
- <td>{{ form.email.label_tag }}</td>
- <td>
-{% if form.email.errors %}
- {{ form.email.errors }}
+<section class="hero is-primary is-fullheight">
+ <div class="hero-body">
+ <div class="container">
+ <div class="columns is-centered">
+ <div class="column is-6-tablet is-6-desktop is-6-widescreen">
+ <div class="block has-text-centered">
+ <h1 class="title is-3">Create your Patchwork account</h1>
+ </div>
+{% if form.non_field_errors %}
+ <div class="notification is-danger is-light">
+ <button class="delete"></button>
+ {{ form.non_field_errors }}
+ </div>
{% endif %}
- {{ form.email }}
-{% if form.email.help_text %}
- <div class="help_text"/>{{ form.email.help_text }}</div>
-{% endif %}
- </td>
- </tr>
- <tr>
- <td></td>
- <td class="form-help">
- Patchwork will send a confirmation email to this address
- </td>
- </tr>
- <tr>
- <td>{{ form.username.label_tag }}</td>
- <td>
-{% if form.username.errors %}
- {{ form.username.errors }}
-{% endif %}
- {{ form.username }}
-{% if form.username.help_text %}
- <div class="help_text"/>{{ form.username.help_text }}</div>
-{% endif %}
- </td>
- </tr>
- <tr>
- <td>{{ form.password.label_tag }}</td>
- <td>
-{% if form.password.errors %}
- {{ form.password.errors }}
-{% endif %}
- {{ form.password }}
-{% if form.password.help_text %}
- <div class="help_text"/>{{ form.password.help_text }}</div>
-{% endif %}
- </td>
- </tr>
- <tr>
- <td colspan="2" class="submitrow">
- <input type="submit" value="Register"/>
- </td>
- </tr>
- </table>
-</form>
+{% for message in messages %}
+{% if message.tags == 'success' %}
+ <div class="notification is-success is-light">
+{% elif message.tags == 'warning' %}
+ <div class="notification is-warning is-light">
+{% elif message.tags == 'error' %}
+ <div class="notification is-danger is-light">
+{% else %}
+ <div class="notification is-light">
{% endif %}
+ <button class="delete" onclick="dismiss(this);"></button>
+ {{ message }}
+ </div>
+{% endfor %}
+ <form method="post" class="box">
+ {% csrf_token %}
+ <div class="field">
+ <label for="id_username" class="label has-text-weight-normal">Username</label>
+ <div class="control has-icons-left">
+ <input id="id_username" type="text" name="username" placeholder="e.g. bobsmith" class="input" autocomplete="username" autofocus required>
+ <span class="icon is-small is-left">
+ <i class="fa fa-user"></i>
+ </span>
+ </div>
+{% for error in form.username.errors %}
+ <p class="help is-danger">{{ error }}</p>
+{% endfor %}
+ </div>
+ <div class="field">
+ <label for="id_email" class="label has-text-weight-normal">Email</label>
+ <div class="control has-icons-left">
+ <input id="id_email" type="email" name="email" placeholder="e.g. bobsmith@example.com" class="input" autocomplete="email" autofocus required>
+ <span class="icon is-small is-left">
+ <i class="fa fa-envelope"></i>
+ </span>
+ </div>
+{% for error in form.email.errors %}
+ <p class="help is-danger">{{ error }}</p>
+{% endfor %}
+ </div>
+ <div class="field">
+ <label for="id_first_name" class="label has-text-weight-normal">First name</label>
+ <div class="control has-icons-left">
+ <input id="id_first_name" type="text" name="first_name" class="input" autocomplete="given-name" autofocus required>
+ <span class="icon is-small is-left">
+ </span>
+ </div>
+{% for error in form.first_name.errors %}
+ <p class="help is-danger">{{ error }}</p>
+{% endfor %}
+ </div>
+ <div class="field">
+ <label for="id_last_name" class="label has-text-weight-normal">Last name</label>
+ <div class="control has-icons-left">
+ <input id="id_last_name" type="text" name="last_name" class="input" autocomplete="family-name" autofocus required>
+ <span class="icon is-small is-left">
+ </span>
+ </div>
+{% for error in form.last_name.errors %}
+ <p class="help is-danger">{{ error }}</p>
+{% endfor %}
+ </div>
+ <div class="field">
+ <label for="id_password" class="label has-text-weight-normal">Password</label>
+ <div class="control has-icons-left">
+ <input id="id_password" type="password" name="password" placeholder="*******" class="input" autocomplete="current-password" required>
+ <span class="icon is-small is-left">
+ <i class="fa fa-lock"></i>
+ </span>
+ </div>
+{% for error in form.password.errors %}
+ <p class="help is-danger">{{ error }}</p>
+{% endfor %}
+ </div>
+ <div class="field">
+ <button class="button is-success is-fullwidth">
+ Sign up
+ </button>
+ </div>
+ </form>
+ <div class="box has-text-centered">
+ <a href="{% url 'auth_login' %}">Log in</a>
+ •
+ <a href="{% url 'password_reset' %}">Forgot Password</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</section>
{% endblock %}
@@ -81,11 +81,18 @@ def register(request):
[confirmation.email]
)
except smtplib.SMTPException:
- context['confirmation'] = None
- context['error'] = (
- 'An error occurred during registration. '
- 'Please try again later'
+ messages.error(
+ request,
+ 'An error occurred while submitting this request. '
+ 'Please contact an administrator.'
+ )
+ else:
+ messages.success(
+ request,
+ 'Succesfully signed up. '
+ 'Check your email for confirmation.',
)
+ return HttpResponseRedirect(reverse('project-list'))
else:
form = RegistrationForm()
This is the last of our non submission pages. There's nothing too tricky here except that we no longer use this page for success, instead directing to the index page, and we remove a potential information leak from the registration form that could leak information about registered users without authentication. Next up, the main patch and cover letter list/detail pages. Signed-off-by: Stephen Finucane <stephen@that.guru> --- patchwork/forms.py | 7 +- .../templates/patchwork/registration.html | 211 +++++++++--------- patchwork/views/user.py | 15 +- 3 files changed, 120 insertions(+), 113 deletions(-)