From 5738c44c9eb92b4349f7721600c1f46f8d79c26a Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Thu, 26 Oct 2023 21:36:18 -0700 Subject: [PATCH] Less error prone username and password creation. --- src/components/concepts/MarkupHTMLView.svelte | 34 ++--- src/locale/UITexts.ts | 6 +- src/locale/en-US.json | 14 +- src/routes/login/Login.svelte | 122 +++++++++++------- static/locales/es-MX/es-MX.json | 5 +- static/locales/example/example.json | 5 +- static/locales/zh-CN/zh-CN.json | 5 +- static/schemas/Locale.json | 15 ++- 8 files changed, 127 insertions(+), 79 deletions(-) diff --git a/src/components/concepts/MarkupHTMLView.svelte b/src/components/concepts/MarkupHTMLView.svelte index 2befcfd4b..9c0091076 100644 --- a/src/components/concepts/MarkupHTMLView.svelte +++ b/src/components/concepts/MarkupHTMLView.svelte @@ -44,25 +44,27 @@ {#each parsed.asLine().paragraphs[0].segments as segment} {/each} - {:else}{#each paragraphsAndLists as paragraphOrList, index}

0} - style="--delay:{$animationDuration * index * 0.1}ms" - >{#if paragraphOrList instanceof Paragraph} - {#each paragraphOrList.segments as segment} 0} + style="--delay:{$animationDuration * index * 0.1}ms" + >{#each paragraphOrList.segments as segment}{/each}{:else}

{/if}

{/each} + />{/each}

{:else}{/if}{/each} {/if} {:else}no spaces{/if} diff --git a/src/locale/UITexts.ts b/src/locale/UITexts.ts index 0b5d08868..54781d85e 100644 --- a/src/locale/UITexts.ts +++ b/src/locale/UITexts.ts @@ -667,9 +667,11 @@ type UITexts = { /** Encouragement to go create after logging in. */ play: string; /** Gives rules for emails above the login form */ - emailrules: string; + emailrules: string[]; /** Gives rules for usernames and passwords above the login form */ - usernamerules: string; + usernamerules: string[]; + /** Reminder to write down password */ + passwordreminder: string; /** Offers to log out the creator. */ logout: string; /** Shown briefly before page redirects to projects */ diff --git a/src/locale/en-US.json b/src/locale/en-US.json index 30b7bfe2d..b9413f9f7 100644 --- a/src/locale/en-US.json +++ b/src/locale/en-US.json @@ -4196,8 +4196,16 @@ }, "enter": "It looks like your login link came from a different browser or device. Can you enter your email again, just so we're sure it's you?", "play": "You're logged in, we can save your projects online now! Want to create something?", - "emailrules": "Don't provide your email if you are 12 or younger.", - "usernamerules": "If you're creating an account, *usernames* should not contain identiable information (e.g., names), cannot be an email addresses, and should be at least 5 characters long. *Passwords* must be at least 10 characters long; if you're not using a password manager, choose three long words you'll remember.", + "emailrules": [ + "• Don't provide your email if you are *12 or younger*.", + "• If you *lose access* to your email account, you won't be able to update your email address." + ], + "usernamerules": [ + "• *Usernames* should not contain identiable information (e.g., names), cannot be an email addresses, and should be at least 5 characters long", + "• *Passwords* must be at least 10 characters long; if you're not using a password manager, choose three long words you'll remember.", + "• *If you forget your password*, you can't recover your account, since we have no other way to know it's you. Store your password somewhere safe, like a password manager" + ], + "passwordreminder": "It looks like you're creating an account. Reveal it above, and make sure you wrote it down correctly, then submit again to create your account.", "change": "Want to change your email? Submit a new one and we'll send a confirmation to the old one.", "sent": "Check your email for a login link. Patience, email can be slow!", "logout": "Leaving a shared device and want to keep your projects private? Logout and we'll remove your projects from this device. They will still be stored online.", @@ -4215,7 +4223,7 @@ "offline": "You appear to be offline.", "unchanged": "We couldn't change your email address, but we don't know why.", "delete": "We couldn't delete your account, but we don't know why.", - "wrongPassword": "Not a valid username and password" + "wrongPassword": "Not a valid username and password. Either your password is wrong, or someone else has this username." }, "feedback": { "changing": "Submitting new email...", diff --git a/src/routes/login/Login.svelte b/src/routes/login/Login.svelte index 9ee6ec86b..682cb1f91 100644 --- a/src/routes/login/Login.svelte +++ b/src/routes/login/Login.svelte @@ -22,7 +22,6 @@ import Mode from '../../components/widgets/Mode.svelte'; import Subheader from '../../components/app/Subheader.svelte'; import MarkupHtmlView from '../../components/concepts/MarkupHTMLView.svelte'; - import Note from '../../components/widgets/Note.svelte'; import { CreatorUsernameEmailDomain } from '../../db/CreatorDatabase'; let user = getUser(); @@ -36,11 +35,17 @@ let younger = true; let username = ''; let password = ''; + let reveal = false; + + $: emailUsername = `${username}${CreatorUsernameEmailDomain}`; + + /** True if we tried to log in and there's no account. */ + let noAccount = false; $: emailSubmittable = !sent && validEmail(email); - $: usernameSubmittable = - !sent && isValidUsername(username) && isValidPassword(password); + $: userNameValid = isValidUsername(username) && isValidPassword(password); + $: usernameIsCheckable = !noAccount && userNameValid; function isValidUsername(username: string) { return !validEmail(username) && username.length >= 5; @@ -114,33 +119,33 @@ return undefined; } - async function startUsernameLogin() { - const emailUsername = `${username}${CreatorUsernameEmailDomain}`; - if (auth && usernameSubmittable) { + async function tryUsernameLogin() { + if (auth && usernameIsCheckable) { try { - await signInWithEmailAndPassword( - auth, - `${username}${CreatorUsernameEmailDomain}`, - password - ); + await signInWithEmailAndPassword(auth, emailUsername, password); } catch (error) { - // If not found, then we create the user. if ( error instanceof FirebaseError && error.code === 'auth/user-not-found' ) { - try { - await createUserWithEmailAndPassword( - auth, - emailUsername, - password - ); - } catch (error) { - usernameLoginFeedback = communicateError(error); - } + noAccount = true; + } else { + usernameLoginFeedback = communicateError(error); } - // Otherwise, communicate the error. - else usernameLoginFeedback = communicateError(error); + } + } + } + + async function createUsernameLogin() { + if (auth && reveal) { + try { + await createUserWithEmailAndPassword( + auth, + emailUsername, + password + ); + } catch (error) { + usernameLoginFeedback = communicateError(error); } } } @@ -187,12 +192,6 @@ {$locales.get((l) => l.ui.page.login.subheader.email)}