Skip to content

Commit cfd0769

Browse files
committed
fix(accounts): address jimchamp + Mek review feedback on OTP login
- Move @internetarchive/elements to devDependencies (matches OL convention; all other JS deps are devDependencies) - Button: use OL primary-blue CSS var, full width, margin-top spacing, and correct hover state to match existing Log In button - Keep modal open on overlay click when user is in code-entry step — avoids losing flow when switching back from email client - Rename redeem_otp() parameter password→otp for clarity; update xauth() kwarg and fake xauth endpoint check to match - Move OTP login section above password form (right after Google sign-in) per Mek's request
1 parent a66946e commit cfd0769

6 files changed

Lines changed: 37 additions & 15 deletions

File tree

openlibrary/accounts/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,12 @@ def issue_otp(cls, email, service="ol", originating_ip=None):
866866
)
867867

868868
@classmethod
869-
def redeem_otp(cls, email, password, originating_ip=None):
869+
def redeem_otp(cls, email, otp, originating_ip=None):
870870
headers = {"X-Originating-IP": originating_ip} if originating_ip else None
871871
return cls.xauth(
872872
"redeem_otp",
873873
email=email.strip().lower(),
874-
password=password,
874+
otp=otp,
875875
headers=headers,
876876
)
877877

openlibrary/components/lit/OpenLibraryOTP.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@ export class OpenLibraryOTP extends LitElement {
4848
}
4949
5050
.trigger-btn {
51-
background: var(--ia-button-primary-bg, #4b4bdf);
51+
background: var(--primary-blue, hsl(202, 96%, 37%));
5252
color: var(--ia-button-primary-color, #fff);
5353
border: none;
5454
border-radius: 4px;
5555
padding: 8px 16px;
5656
font-size: 1rem;
5757
font-family: inherit;
5858
cursor: pointer;
59-
width: fit-content;
59+
width: 100%;
60+
margin-top: 10px;
6061
}
6162
.trigger-btn:hover,
6263
.trigger-btn:focus {
63-
background: var(--ia-button-primary-bg-hover, #3a3abf);
64+
background: hsl(202, 96%, 17%);
6465
outline: 2px solid currentColor;
6566
outline-offset: 2px;
6667
}
@@ -288,6 +289,10 @@ export class OpenLibraryOTP extends LitElement {
288289
}
289290

290291
_handleOverlayClick(e) {
292+
// Keep the modal open while the user is entering their code — they are
293+
// likely switching back from their email client and an accidental click
294+
// should not lose their place in the flow.
295+
if (this._step === 'code') return;
291296
if (e.target === e.currentTarget) this._closeModal();
292297
}
293298

openlibrary/plugins/upstream/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def POST(self):
161161
result = {"success": True, "version": 1}
162162
elif i.op == "redeem_otp":
163163
# Accept "123456" as the dev OTP code
164-
if body.get("password") == "123456":
164+
if body.get("otp") == "123456":
165165
result = {
166166
"success": True,
167167
"version": 1,

openlibrary/templates/login.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ <h1 class="ol-signup-hero__title">$_("Log In")</h1>
4242
<p>$:_('If you\'d like to create a new, different Open Library account, you\'ll need to <a href="javascript:;" onclick="document.forms[\'hamburger-logout\'].submit()">log out</a> and start the signup process afresh.')</p>
4343

4444
$else:
45+
<ol-otp-login redirect="$(form.redirect.value or '/account/books')"></ol-otp-login>
46+
<div class="ol-signup-form__big-or">$_('OR')</div>
4547
<form id="register" class="login olform" name="login" method="post" data-i18n="$json_encode(i18n_strings)">
4648
$if form.note:
4749
<div class="flash-messages">
@@ -94,7 +96,5 @@ <h1 class="ol-signup-hero__title">$_("Log In")</h1>
9496
<p class="ol-signup-form__login-hint">$:_('Don\'t have an account? <a href="/account/create">Sign up now</a>.')</p>
9597
</form>
9698

97-
<div class="ol-signup-form__big-or">$_('OR')</div>
98-
<ol-otp-login redirect="$(form.redirect.value or '/account/books')"></ol-otp-login>
9999
</div>
100100
</div>

package-lock.json

Lines changed: 22 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"build-storybook": "cd stories && npm install --no-audit && npx storybook build"
2929
},
3030
"devDependencies": {
31+
"@internetarchive/elements": "^0.2.5",
3132
"@babel/core": "^7.24.7",
3233
"@babel/eslint-parser": "^7.28.6",
3334
"@babel/preset-env": "^7.29.3",
@@ -130,8 +131,5 @@
130131
"Safari >= 11.1",
131132
"iOS >= 11.3",
132133
"Android >= 5"
133-
],
134-
"dependencies": {
135-
"@internetarchive/elements": "^0.2.5"
136-
}
134+
]
137135
}

0 commit comments

Comments
 (0)