From 283909eabdf3e679c2cf25f1a6f4adddad9bfc4e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 9 Sep 2020 13:24:36 +0300 Subject: [PATCH] Migration: add signup. --- src/MigrateV2.tsx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/MigrateV2.tsx b/src/MigrateV2.tsx index 97dc4e2..ac77f1f 100644 --- a/src/MigrateV2.tsx +++ b/src/MigrateV2.tsx @@ -44,12 +44,14 @@ export default function MigrateV2(props: PropsType) { const [username, setUsername] = React.useState(""); const [password, setPassword] = React.useState(""); const [server, setServer] = React.useState(""); + const [hasAccount, setHasAccount] = React.useState(false); const [showAdvanced, setShowAdvanced] = React.useState(false); const [loading, setLoading] = React.useState(false); const [progress, setProgress] = React.useState(""); const [errors, setErrors] = React.useState({}); const journals = useSelector((state: StoreState) => state.cache.journals!); const journalEntries = useSelector((state: StoreState) => state.cache.entries); + const email = props.etesync.credentials.email; const derived = props.etesync.encryptionKey; const decryptedJournals = React.useMemo(() => { @@ -152,8 +154,18 @@ export default function MigrateV2(props: PropsType) { const serverUrl = (showAdvanced) ? server : undefined; let malformed = 0; - setProgress("Logging into EteSync 2.0 account"); - const etebase = await Etebase.Account.login(username, password, serverUrl); + let etebase: Etebase.Account; + if (hasAccount) { + setProgress("Logging into EteSync 2.0 account"); + etebase = await Etebase.Account.login(username, password, serverUrl); + } else { + setProgress("Logging into EteSync 2.0 account"); + const user: Etebase.User = { + username, + email, + }; + etebase = await Etebase.Account.signup(user, password, serverUrl); + } const colMgr = etebase.getCollectionManager(); const { etesync, userInfo } = props; @@ -327,6 +339,11 @@ export default function MigrateV2(props: PropsType) {

EteSync 2.0 credentials

+ setHasAccount(!hasAccount)} />} + label="I already have an EteSync 2.0 account" + /> +
+ {!hasAccount && ( + + Please make sure you remember your password, as it can't be recovered if lost! + + )} {loading ? ( - ) : "Migrate" + ) : (hasAccount) ? "Login & Migrate" : "Signup & Migrate" }