Skip to content

Commit 30e7727

Browse files
author
Yeray Diaz Diaz
committed
Add password match feature to register and reset password forms
1 parent c18eb36 commit 30e7727

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

warehouse/templates/accounts/register.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div class="site-container">
2424
<h1 class="page-title">Create an account on PyPI</h1>
2525

26-
<form method="POST" action="{{ request.current_route_path() }}">
26+
<form method="POST" action="{{ request.current_route_path() }}" data-controller="password password-match">
2727
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
2828

2929
{% if form.errors.__all__ %}
@@ -70,7 +70,7 @@ <h1 class="page-title">Create an account on PyPI</h1>
7070
{% endif %}
7171
</div>
7272

73-
<div data-controller="password">
73+
<div>
7474
<div class="form-group">
7575
<div class="split-layout">
7676
<label for="password" class="form-group__label">Password</label>
@@ -81,7 +81,7 @@ <h1 class="page-title">Create an account on PyPI</h1>
8181
</div>
8282
{# the password field needs to be wrapped in a div to properly place tooltips #}
8383
<div>
84-
{{ form.new_password(placeholder="Select a password", required="required", class_="form-group__input", autocomplete="new-password", data_target="password.password") }}
84+
{{ form.new_password(placeholder="Select a password", required="required", class_="form-group__input", autocomplete="new-password", data_target="password.password password-match.passwordMatch", data_action="keyup->password-match#checkPasswordsMatch") }}
8585
</div>
8686
{% if form.new_password.errors %}
8787
<ul class="form-errors">
@@ -95,7 +95,7 @@ <h1 class="page-title">Create an account on PyPI</h1>
9595

9696
<div class="form-group">
9797
<label for="password_confirm" class="form-group__label">Confirm Password</label>
98-
{{ form.password_confirm(placeholder="Confirm password", required="required", class_="form-group__input", data_target="password.password") }}
98+
{{ form.password_confirm(placeholder="Confirm password", required="required", class_="form-group__input", data_target="password.password password-match.passwordMatch", data_action="keyup->password-match#checkPasswordsMatch") }}
9999
{% if form.password_confirm.errors %}
100100
<ul class="form-errors">
101101
{% for error in form.password_confirm.errors %}
@@ -106,11 +106,15 @@ <h1 class="page-title">Create an account on PyPI</h1>
106106
</div>
107107
</div>
108108

109+
<ul class="form-errors">
110+
<li data-target="password-match.matchMessage" class="hidden"></li>
111+
</ul>
112+
109113
<div class="form-group">
110114
{{ recaptcha_html(request, form) }}
111115
</div>
112116

113-
<input type="submit" value="Create Account" class="button button--primary">
117+
<input type="submit" value="Create Account" class="button button--primary" data-target="password-match.submit">
114118
</form>
115119
</div>
116120
</section>

warehouse/templates/accounts/reset-password.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<section class="horizontal-section">
2020
<div class="site-container">
2121
<h1 class="page-title">Reset Your Password</h1>
22-
<form data-controller="password" method="POST" action="{{ request.current_route_path() }}">
22+
<form data-controller="password password-match" method="POST" action="{{ request.current_route_path() }}">
2323
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
2424
{% if form.errors.__all__ %}
2525
<ul class="errors">
@@ -39,7 +39,7 @@ <h1 class="page-title">Reset Your Password</h1>
3939
</div>
4040
{# the password field needs to be wrapped in a div to properly place tooltips #}
4141
<div>
42-
{{ form.new_password(placeholder="Select a new password", required="required", class_="form-group__input", data_target="password.password") }}
42+
{{ form.new_password(placeholder="Select a new password", required="required", class_="form-group__input", data_target="password.password password-match.passwordMatch", data_action="keyup->password-match#checkPasswordsMatch") }}
4343
</div>
4444
{% if form.new_password.errors %}
4545
<ul class="form-errors">
@@ -53,7 +53,7 @@ <h1 class="page-title">Reset Your Password</h1>
5353

5454
<div class="form-group">
5555
<label for="password_confirm" class="form-group__label">Confirm Password</label>
56-
{{ form.password_confirm(placeholder="Confirm password", required="required", class_="form-group__input", data_target="password.password") }}
56+
{{ form.password_confirm(placeholder="Confirm password", required="required", class_="form-group__input", data_target="password.password password-match.passwordMatch", data_action="keyup->password-match#checkPasswordsMatch") }}
5757
{% if form.password_confirm.errors %}
5858
<ul class="form-errors">
5959
{% for error in form.password_confirm.errors %}
@@ -63,7 +63,11 @@ <h1 class="page-title">Reset Your Password</h1>
6363
{% endif %}
6464
</div>
6565

66-
<input type="submit" value="Reset Password" class="button button--primary">
66+
<ul class="form-errors">
67+
<li data-target="password-match.matchMessage" class="hidden"></li>
68+
</ul>
69+
70+
<input type="submit" value="Reset Password" class="button button--primary" data-target="password-match.submit">
6771
</form>
6872
</div>
6973
</section>

0 commit comments

Comments
 (0)