Skip to content

Commit

Permalink
Moving to single password field for registration (internetarchive#7729)
Browse files Browse the repository at this point in the history
* Use localized strings
* Adjust margin for password inputs
---------

Co-authored-by: James Champ <jameschamp@acm.org>
  • Loading branch information
Ari1009 and jimchamp authored Feb 13, 2024
1 parent 3765ba9 commit 5098757
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
6 changes: 6 additions & 0 deletions openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,10 @@ jQuery(function () {
.then(module => module.initBreadcrumbSelect(crumbs));
}

// Password visibility toggle:
const passwordVisibilityToggle = document.querySelector('.password-visibility-toggle')
if (passwordVisibilityToggle) {
import(/* webpackChunkName: "password-visibility-toggle" */ './password-toggle')
.then(module => module.initPasswordToggling(passwordVisibilityToggle))
}
});
19 changes: 19 additions & 0 deletions openlibrary/plugins/openlibrary/js/password-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Adds ability to toggle a password field's visibilty.
*
* @param {HTMLElement} elem Reference to affordance that toggles a password input's visibility
*/
export function initPasswordToggling(elem) {
const i18nStrings = JSON.parse(elem.dataset.i18n)
const passwordInput = document.querySelector('input[type=password]')

elem.addEventListener('click', () => {
if (passwordInput.type === 'password') {
passwordInput.type = 'text'
elem.textContent = i18nStrings['hide_password']
} else {
passwordInput.type = 'password'
elem.textContent = i18nStrings['show_password']
}
})
}
9 changes: 0 additions & 9 deletions openlibrary/plugins/upstream/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ class RegisterForm(Form):
klass='required',
validators=[vpass],
),
Password(
'password2',
description=_('Confirm password'),
klass='required',
validators=[
vpass,
EqualToValidator('password', _("Passwords didn't match.")),
],
),
Checkbox(
'ia_newsletter',
description=_(
Expand Down
10 changes: 7 additions & 3 deletions openlibrary/templates/account/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ <h1>$_("Sign Up")</h1>
</div>
<div class="input">
$:input.render()
$if input.name == 'password':
$ i18n_strings = {
$ "show_password": _('Show password'),
$ "hide_password": _('Hide password')
$ }
<a href="javascript:;" class="password-visibility-toggle" data-i18n="$json_encode(i18n_strings)">$i18n_strings["show_password"]</a>
<span class="invalid clearfix" id="$(input.id)Message">$input.note</span>
<span class="sansserif smaller lighter">$:suffix</span>
</div>
</div>


$if ctx.user:
$def user_link(): <a href="$ctx.user.key">$ctx.user.displayname</a>
<p>$:_("You are already logged into Open Library as %(user)s.", user=str(user_link()))</p>
Expand All @@ -48,9 +55,7 @@ <h1>$_("Sign Up")</h1>
$:field(form.email)
$:field(form.username, suffix=str(screenname_url()))
$:field(form.password)
$:field(form.password2)

<br/>
<label>
$:form.ia_newsletter.render() $:form.ia_newsletter.description
</label>
Expand All @@ -71,5 +76,4 @@ <h1>$_("Sign Up")</h1>
<a href="javascript:history.go(-1);" class="smaller attn">$_("Cancel")</a>
</div>
</form>

</div>
3 changes: 2 additions & 1 deletion static/css/components/form.olform.less
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
}

input[type=number],
input[type=text] {
input[type=text],
input[type=password] {
margin: 0 10px 5px 0;
}

Expand Down

0 comments on commit 5098757

Please sign in to comment.