From a22ab195aea61802521d31900f7f8a39fcb57033 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 13 Sep 2023 14:26:13 -0500 Subject: [PATCH 1/4] Add e-mail verification. --- package.json | 8 +++- src/App.js | 11 +++-- src/components/pages/RegisterPage.js | 41 +++++++++--------- src/components/pages/VerifyPage.js | 64 ++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 src/components/pages/VerifyPage.js diff --git a/package.json b/package.json index 27f62a8..e5e1dc3 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,18 @@ "react-router-dom": "^6.15.0", "react-scripts": "5.0.1" }, + "devDependencies": { + "eslint": "^8.22.0", + "eslint-plugin-simple-import-sort": "^10.0.0" + }, "scripts": { "start": "react-scripts start", "clean": "rm -rf build", "build": "NODE_OPTIONS=--openssl-legacy-provider react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "lint": "eslint src/ --ext .js", + "lint:fix": "eslint src/ --ext .js --fix" }, "eslintConfig": { "extends": "react-app" diff --git a/src/App.js b/src/App.js index 5b9131d..5f58359 100644 --- a/src/App.js +++ b/src/App.js @@ -1,22 +1,21 @@ import React from 'react' import { BrowserRouter as Router, Routes, Route } from 'react-router-dom' -import LandingPage from './components/pages/LandingPage' -import LoginPage from './components/pages/LoginPage' import RegisterPage from './components/pages/RegisterPage' -import ForgetPasswordPage from './components/pages/ForgetPasswordPage' -import HomePage from './components/pages/HomePage' +import VerifyPage from './components/pages/VerifyPage' import './App.css' export default function App() { - const basePath = "LACONIC_HOSTED_CONFIG_web_path" + //const basePath = "LACONIC_HOSTED_CONFIG_web_path" + const basePath = ""; return (
} /> - } /> + } /> + } />
diff --git a/src/components/pages/RegisterPage.js b/src/components/pages/RegisterPage.js index 1f7ffae..eb40314 100644 --- a/src/components/pages/RegisterPage.js +++ b/src/components/pages/RegisterPage.js @@ -5,16 +5,18 @@ import '../../App.css' import {Link} from "react-router-dom"; export default function SignUpPage() { - const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); + const [apiKey, setApiKey] = useState(""); const [message, setMessage] = useState(""); const [error, setError] = useState(""); let handleSubmit = async (e) => { + setApiKey(""); setMessage(""); setError(""); - const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; + //const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; + const apiUrl = "http://localhost:9393"; e.preventDefault(); try { let res = await fetch(`${apiUrl}/register`, { @@ -23,13 +25,18 @@ export default function SignUpPage() { "Content-Type": "application/json", }, body: JSON.stringify({ - username: username, + username: email, email: email, }), }); let resJson = await res.json(); if (res.status === 200) { - setMessage(`${resJson['api-key']}`); + if (resJson['api-key']) { + setApiKey(`${resJson['api-key']}`); + setMessage(`${resJson['api-key']}`); + } else { + setMessage("Success"); + } } else { setError(`An error occurred: ${res.status}`); } @@ -40,37 +47,33 @@ export default function SignUpPage() { return (
- {message ? + {apiKey ?

Account Created

API Key
- {message} + {apiKey}
Save this key. It will not be displayed again.
: + message ? +
+

Account Created

+
+
Verification Required
+ Please check your e-mail for a link to verify your account. +
+
+ :
- {/*

Join us

*/} - {/*
Create your personal account
*/ - }
- {/*

*/} - {/*
*/} - {/* setUsername(e.target.value)}*/} - {/* required />*/} - {/*

*/}


setEmail(e.target.value)} required/>

- {/*

*/} - {/*
*/} - {/* */} - {/*

*/}

I agree all statements in { + //const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; + const apiUrl = "http://localhost:9393"; + let res = await fetch(`${apiUrl}/verify`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + token + }), + }); + + const resJson = await res.json(); + if (res.status === 200) { + return `${resJson['api-key']}`; + } + throw new Error(`An error occurred: ${res.status}`); + }; + + if (!message && !error) { + handleSubmit().then((message) => { + setMessage(message) + }).catch((reason) => { + setError("An error occurred.") + }) + } + + return ( +

+ ) + +} -- 2.45.2 From e404292a005eee977f05db1203f713b7164a104a Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 13 Sep 2023 14:28:43 -0500 Subject: [PATCH 2/4] URLs --- src/App.js | 3 +-- src/components/pages/RegisterPage.js | 3 +-- src/components/pages/VerifyPage.js | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index 5f58359..54b9f0b 100644 --- a/src/App.js +++ b/src/App.js @@ -7,8 +7,7 @@ import VerifyPage from './components/pages/VerifyPage' import './App.css' export default function App() { - //const basePath = "LACONIC_HOSTED_CONFIG_web_path" - const basePath = ""; + const basePath = "LACONIC_HOSTED_CONFIG_web_path" return (
diff --git a/src/components/pages/RegisterPage.js b/src/components/pages/RegisterPage.js index eb40314..98a23dd 100644 --- a/src/components/pages/RegisterPage.js +++ b/src/components/pages/RegisterPage.js @@ -15,8 +15,7 @@ export default function SignUpPage() { setMessage(""); setError(""); - //const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; - const apiUrl = "http://localhost:9393"; + const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; e.preventDefault(); try { let res = await fetch(`${apiUrl}/register`, { diff --git a/src/components/pages/VerifyPage.js b/src/components/pages/VerifyPage.js index fdfa38b..f1a218d 100644 --- a/src/components/pages/VerifyPage.js +++ b/src/components/pages/VerifyPage.js @@ -11,8 +11,7 @@ export default function VerifyPage(props) { const token = query.get("token") let handleSubmit = async () => { - //const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; - const apiUrl = "http://localhost:9393"; + const apiUrl = "LACONIC_HOSTED_CONFIG_api_url"; let res = await fetch(`${apiUrl}/verify`, { method: "POST", headers: { -- 2.45.2 From 616bdaa4225cd5c70b971337153da8c477405e10 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 13 Sep 2023 15:38:55 -0500 Subject: [PATCH 3/4] HashRouter --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 54b9f0b..055cbe5 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,5 @@ import React from 'react' -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom' +import { HashRouter as Router, Routes, Route } from 'react-router-dom' import RegisterPage from './components/pages/RegisterPage' import VerifyPage from './components/pages/VerifyPage' -- 2.45.2 From 4520af4c550ac986b4fb59aec6def9ba28e36848 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 13 Sep 2023 21:21:54 +0000 Subject: [PATCH 4/4] No need for base path. --- src/App.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 055cbe5..c973ebf 100644 --- a/src/App.js +++ b/src/App.js @@ -7,14 +7,13 @@ import VerifyPage from './components/pages/VerifyPage' import './App.css' export default function App() { - const basePath = "LACONIC_HOSTED_CONFIG_web_path" return (
- } /> - } /> - } /> + } /> + } /> + } />
-- 2.45.2