Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registration errors from xauthn #10402

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions openlibrary/accounts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,19 +688,23 @@ def create(
ia_account.test = True
return ia_account

elif 'screenname' not in response.get('values', {}):
error = OLAuthenticationError('undefined_error')
error.response = response
raise error

elif attempt >= retries:
# Response has returned "failure" with reasons in "values"
failures = response.get('values', {})
if 'screenname' not in failures:
for field in failures:
# raise the first error if multiple
# e.g. bad_email, bad_password
error = OLAuthenticationError(f'bad_{field}')
error.response = response
raise error
elif attempt < retries:
_screenname = append_random_suffix(screenname)
attempt += 1
else:
e = OLAuthenticationError('username_registered')
e.value = _screenname
raise e

_screenname = append_random_suffix(screenname)
attempt += 1

@classmethod
def xauth(cls, op, test=None, s3_key=None, s3_secret=None, xauth_url=None, **data):
"""
Expand Down
25 changes: 19 additions & 6 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,6 @@ msgstr ""
msgid "OR"
msgstr ""

#: login.html
msgid ""
"Please enter your <a href=\"https://archive.org\">Internet Archive</a> "
"email and password to access your Open Library account."
msgstr ""

#: account/create.html login.html
#, python-format
msgid "You are already logged into Open Library as %(user)s."
Expand All @@ -503,6 +497,12 @@ msgid ""
"logout'].submit()\">log out</a> and start the signup process afresh."
msgstr ""

#: login.html
msgid ""
"Please enter your <a href=\"https://archive.org\">Internet Archive</a> "
"email and password to access your Open Library account."
msgstr ""

#: forms.py login.html
msgid "Email"
msgstr ""
Expand Down Expand Up @@ -7828,10 +7828,23 @@ msgid ""
"or email openlibrary@archive.org for help."
msgstr ""

#: account.py
msgid "Email provider not recognized."
msgstr ""

#: account.py
msgid "Password requirements not met."
msgstr ""

#: account.py
msgid "A problem occurred and we were unable to log you in"
msgstr ""

#: account.py
#, python-format
msgid "Request failed with error code: %(error_code)s"
msgstr ""

#: account.py
#, python-format
msgid ""
Expand Down
8 changes: 7 additions & 1 deletion openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ def get_login_error(error_key):
"request_timeout": _(
"Servers are experiencing unusually high traffic, please try again later or email openlibrary@archive.org for help."
),
"bad_email": _("Email provider not recognized."),
"bad_password": _("Password requirements not met."),
"undefined_error": _('A problem occurred and we were unable to log you in'),
}
return LOGIN_ERRORS[error_key]
return (
LOGIN_ERRORS[error_key]
if error_key in LOGIN_ERRORS
else _("Request failed with error code: %(error_code)s", error_code=error_key)
)


class availability(delegate.page):
Expand Down
8 changes: 7 additions & 1 deletion openlibrary/templates/account/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ <h1 class="ol-signup-hero__title">$_("Sign Up")</h1>
$else:
<form class="olform create create-form" name="signup" method="post" data-i18n="$json_encode(i18n_strings)" action="">
$if form.note:
<div class="ol-signup-form__note">$form.note</div>
<div class="flash-messages">
<div class="error ol-signup-form__info-box">
<span>
$:form.note
</span>
</div>
</div>

$def screenname_url(): $_('Your URL'): https://openlibrary.org/people/<span id="userUrl">$(form.username.value or _('screenname'))</span>

Expand Down
11 changes: 8 additions & 3 deletions openlibrary/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ <h1 class="ol-signup-hero__title">$_("Log In")</h1>
$if not ctx.user:
$:render_template("account/ia_thirdparty_logins")
<div class="ol-signup-form__big-or">$_('OR')</div>
<div class="ol-signup-form__info">$:_('Please enter your <a href="https://archive.org">Internet Archive</a> email and password to access your Open Library account.')</div>

$if ctx.user:
<p>$:_("You are already logged into Open Library as %(user)s.", user='<a href="%s">%s</a>' % (ctx.user.key, ctx.user.displayname))</p>
Expand All @@ -38,8 +37,14 @@ <h1 class="ol-signup-hero__title">$_("Log In")</h1>
$else:
<form id="register" class="login olform" name="login" method="post" data-i18n="$json_encode(i18n_strings)">
$if form.note:
<div class="note">$form.note</div>

<div class="flash-messages">
<div class="error ol-signup-form__info-box">
<span>
$:form.note
</span>
</div>
</div>
<div class="ol-signup-form__info">$:_('Please enter your <a href="https://archive.org">Internet Archive</a> email and password to access your Open Library account.')</div>
<div class="formElement ol-signup-form__input">
<div class="label">
<label for="username">$_("Email")</label>
Expand Down
Loading