From e2cf9939f5961cac19d255c4852d5adf5f076f17 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 25 Nov 2022 00:12:17 +0200 Subject: [PATCH] registration page --- src/App.js | 68 +++++++++++++++++++++++++------------------ src/css/index.css | 4 +++ src/pages/Login.js | 20 +++++++++---- src/pages/Register.js | 49 +++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 34 deletions(-) create mode 100644 src/pages/Register.js diff --git a/src/App.js b/src/App.js index f9a6562..d466c94 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ import { UnauthedRoute } from './structures/UnauthedRoute'; import Users from './pages/Users'; import Admin from './pages/Admin'; import TitledPage from './components/TitledPage'; +import Register from './pages/Register'; function App() { @@ -29,7 +30,7 @@ function App() { }, []); const menuItems = [ - { to: '/home', label: 'Home' }, + { to: '/home', label: 'Home', items: [{ to: '/profile', label: 'Profile', relative: false }] }, { to: '/users', label: 'Users' }, { to: '/admin', label: 'Admin' } ]; @@ -38,10 +39,10 @@ function App() { return (
- +
- + {user ?
@@ -54,34 +55,45 @@ function App() {
: null} -
- - - - - - - } /> - - - - - } /> - - - } /> - - - } /> - } /> - - -
+
+ + + + + + + + } /> + + + + + + } /> + + + + } /> + + + } /> - + + + } /> + + } /> + + + + +
-
+ + +
+ ); diff --git a/src/css/index.css b/src/css/index.css index 1892507..22d8df7 100644 --- a/src/css/index.css +++ b/src/css/index.css @@ -18,6 +18,10 @@ --font-family-mono: monaco, "Consolas", "Lucida Console", monospace; } +.clickable { + cursor: pointer; +} + a:hover:not(.button){ opacity: 1 !important; color: #C4C4C4; diff --git a/src/pages/Login.js b/src/pages/Login.js index 2d246f6..46f8ab5 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -25,17 +25,17 @@ const CredentialFields = () => { if (!username.length || !password.length) return; const result = await post('/api/login', { username, password }); - console.log(result); + if (![200, 302].includes(result.status)) { setFail(true); return; } - if (!result.data.twoFactor) { + if (!result.data?.twoFactor) { setUser(await fetchUser()); return navigate('/home'); } - return navigate('/login/verify'); + return navigate('verify'); }; @@ -43,13 +43,21 @@ const CredentialFields = () => {
+
{fail ?

Invalid credentials

: null}

Log in

- - - +
+ + + +
+ +
+ Don't ave an account? navigate('/register')} className="clickable">Register instead +
+
diff --git a/src/pages/Register.js b/src/pages/Register.js new file mode 100644 index 0000000..ea401d9 --- /dev/null +++ b/src/pages/Register.js @@ -0,0 +1,49 @@ +import React, { useState } from "react"; +import { useNavigate, useSearchParams } from "react-router-dom"; +import { post } from "../util/Util"; + +// TODO: Make this page look similar to the login page, probably generalise the components +const Register = () => { + + const [error, setError] = useState(); + const [params] = useSearchParams(); + const navigate = useNavigate(); + + document.body.classList.add('bg-triangles'); + const code = params.get('code'); + + const submit = async () => { + const username = document.getElementById('username').value; + const password = document.getElementById('password').value; + if (!username.length || !password.length) return; + + const response = await post('/api/register', { username, password, code }); + if (response.status !== 200) return setError(response.message); + navigate('/login'); + }; + + return
+ +
+
+

Register

+ + {error &&

{error}

} + +
+ + + +
+ + + +
+
+
; + +}; + +export default Register; \ No newline at end of file