diff --git a/.envdev b/.envdev index 0d4ed8c..fb8aa9a 100644 --- a/.envdev +++ b/.envdev @@ -1,20 +1,9 @@ -WEB_PROTOCOL=http -WEB_ADDRESS=localhost WEB_PORT=3000 -MAIL_SMTP=smtp.example.com -MAIL_USERNAME=foobar@example.com -MAIL_PASSWORD=foobar -MAIL_PHYSICAL=42 Placeholder Ave, Placeholder, 0000, USA - -DB_HOSTNAME=127.0.0.1 +DB_HOSTNAME=database DB_DATABASE=template DB_USERNAME=template DB_PASSWORD=pikachu DB_TIMEZONE=Australia/Sydney -CHAT_URI=http://example.com:3200/chat -CHAT_KEY=chattychattybangbang - -SESSION_SECRET=secret -SESSION_ADMIN=adminsecret \ No newline at end of file +SECRET_ACCESS=access \ No newline at end of file diff --git a/client/client.jsx b/client/client.jsx index a7e1286..e98275d 100644 --- a/client/client.jsx +++ b/client/client.jsx @@ -1,16 +1,12 @@ //polyfills -import 'core-js/stable'; import 'regenerator-runtime/runtime'; import React from 'react'; import ReactDOM from 'react-dom'; -import { CookiesProvider } from 'react-cookie'; import App from './components/app'; ReactDOM.render( - - - , + , document.querySelector('#root') ); diff --git a/client/components/app.jsx b/client/components/app.jsx index 5e66b85..7f53509 100644 --- a/client/components/app.jsx +++ b/client/components/app.jsx @@ -1,7 +1,6 @@ //react -import React, { useState } from 'react'; +import React from 'react'; import { BrowserRouter, Switch } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; //library components import LazyRoute from './lazy-route'; @@ -15,24 +14,6 @@ import Header from './panels/header.jsx'; import Footer from './panels/footer.jsx'; const App = props => { - //handle cookies prompt - const [cookies, setCookie] = useCookies(); - - if (!cookies['accept-cookies']) { - const accept = confirm('This website uses cookies to operate correctly. By clicking "ok", you agree to accept said cookies.'); - - if (accept) { - setCookie('accept-cookies', true); - } else { - return ( -
-

This website won't operate correctly without cookies.

- -
- ); - } - } - //default render return ( @@ -40,13 +21,6 @@ const App = props => { import('./pages/homepage')} /> - import('./pages/signup')} /> - import('./pages/login')} /> - import('./pages/account')} /> - import('./pages/chat')} /> - - import('./pages/admin')} /> - () => } /> () => } /> diff --git a/client/components/pages/account.jsx b/client/components/pages/account.jsx deleted file mode 100644 index 0dac79f..0000000 --- a/client/components/pages/account.jsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useEffect } from 'react'; -import { Redirect } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; - -import DeleteAccount from '../panels/delete-account'; - -const Account = props => { - const [cookies, setCookie] = useCookies(); - - //check for logged in redirect - if (!cookies['loggedin']) { - return ; - } - - //refs - let contactElement, passwordElement, retypeElement; - - //once before render - useEffect(() => { - fetch('/api/accounts') - .then(blob => blob.json()) - .then(json => { - contactElement.checked = json.contact; - }) - .catch(e => console.error(e)) - ; - }, []); - - return ( -
-

Account

-
{ - evt.preventDefault(); - await update(contactElement.checked, passwordElement.value, retypeElement.value); - passwordElement.value = retypeElement.value = ''; - }}> -
-
- - contactElement = e} /> -
- -
- - passwordElement = e} /> -
- -
- - retypeElement = e} /> -
-
- - -
- - -
- ); -}; - -const update = async (contact, password, retype) => { - if (password != retype) { - alert('Passwords do not match'); - } - - //generate a new formdata payload - let formData = new FormData(); - - formData.append('contact', contact); - - if (password) { - formData.append('password', password); - } - - const result = await fetch('/api/accounts', { method: 'PATCH', body: formData }); - - if (result.ok) { - alert(await result.text()); - } else { - alert(await result.text()); - } -} - -export default Account; diff --git a/client/components/pages/admin.jsx b/client/components/pages/admin.jsx deleted file mode 100644 index 936708b..0000000 --- a/client/components/pages/admin.jsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import { Redirect } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; - -//import BannedEmails from '../panels/banned-emails'; -import NewsPublisher from '../panels/news-publisher'; -import NewsEditor from '../panels/news-editor'; - -const Admin = props => { - const [cookies, setCookie] = useCookies(); - - //check for logged in redirect - if (!cookies['admin']) { - return ; - } - - return ( -
-

Administration

- - -
- ); -}; - -export default Admin; diff --git a/client/components/pages/chat.jsx b/client/components/pages/chat.jsx deleted file mode 100644 index 13494c6..0000000 --- a/client/components/pages/chat.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import { Redirect } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; - -import Chat from '../panels/chat'; - -//Temporary chat page -const ChatPage = props => { - const [cookies, setCookie] = useCookies(); - - //check for logged in redirect - if (!cookies['loggedin']) { - return ; - } - - return ( -
- -
- ); -}; - -export default ChatPage; \ No newline at end of file diff --git a/client/components/pages/login.jsx b/client/components/pages/login.jsx deleted file mode 100644 index 6613d22..0000000 --- a/client/components/pages/login.jsx +++ /dev/null @@ -1,71 +0,0 @@ -import React from 'react'; -import { Redirect } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; - -//utilities -const validateEmail = require('../../../common/utilities/validate-email.js'); - -const LogIn = props => { - const [cookies, setCookie] = useCookies(); - - //check for logged in redirect - if (cookies['loggedin']) { - return ; - } - - //refs - let emailElement, passwordElement; - - return ( -
-

Login

-
{ - evt.preventDefault(); - handleSubmit(emailElement.value, passwordElement.value) - .then(([res, ok]) => { - alert(res); - if (ok) { - window.location.reload(true); //BUFGIX: force reload of the header element - } - }) - .catch(e => console.error(e)) - ; - } - }> -
- - emailElement = e} /> -
- -
- - passwordElement = e} /> -
- - -
-
- ); -}; - -//DOCS: returns two values: response and OK -const handleSubmit = async (email, password) => { - email = email.trim(); - - //generate a new formdata payload - let formData = new FormData(); - - formData.append('email', email); - formData.append('password', password); - - const result = await fetch('/api/accounts/login', { method: 'POST', body: formData }); - - if (result.ok) { - return [await result.text(), true]; - } else { - return [await result.text(), false]; - } -}; - -export default LogIn; diff --git a/client/components/pages/not-found.jsx b/client/components/pages/not-found.jsx index 0f694bb..bd080b1 100644 --- a/client/components/pages/not-found.jsx +++ b/client/components/pages/not-found.jsx @@ -3,7 +3,7 @@ import React from 'react'; const NotFound = props => { return (
-

Not Found

+

Page Not Found

); }; diff --git a/client/components/pages/signup.jsx b/client/components/pages/signup.jsx deleted file mode 100644 index 43c4726..0000000 --- a/client/components/pages/signup.jsx +++ /dev/null @@ -1,114 +0,0 @@ -import React from 'react'; -import { Redirect } from 'react-router-dom'; -import { useCookies } from 'react-cookie'; - -//utilities -const validateEmail = require('../../../common/utilities/validate-email.js'); -const validateUsername = require('../../../common/utilities/validate-username.js'); - -const SignUp = props => { - const [cookies, setCookie] = useCookies(); - - //check for logged in redirect - if (cookies['loggedin']) { - return ; - } - - //refs - let emailElement, usernameElement, passwordElement, retypeElement, contactElement; - - return ( -
-

Signup

-
{ - evt.preventDefault(); - handleSubmit(emailElement.value, usernameElement.value, passwordElement.value, retypeElement.value, contactElement.checked) - .then(res => res ? alert(res) : null) - .then(() => emailElement.value = usernameElement.value = passwordElement.value = retypeElement.value = '') //clear input - .then(() => contactElement.checked = false) - .then(() => props.history.push('/')) - .catch(e => console.error(e)) - ; - } - }> -
- - emailElement = e} /> -
- -
- - usernameElement = e} /> -
- -
- - passwordElement = e} /> -
- -
- - retypeElement = e} /> -
- -
- - contactElement = e} /> -
- - -
-
- ); -}; - -const handleSubmit = async (email, username, password, retype, contact) => { - email = email.trim(); - username = username.trim(); - - const err = handleValidation(email, username, password, retype); - - if (err) { - return err; - } - - //generate a new formdata payload - let formData = new FormData(); - - formData.append('email', email); - formData.append('username', username); - formData.append('password', password); - formData.append('contact', contact) - - const result = await fetch('/api/accounts/signup', { method: 'POST', body: formData }); - - if (result.ok) { - return result.text(); - } else { - return result.text(); - } -}; - -//returns an error message, or null on success -const handleValidation = (email, username, password, retype) => { - if (!validateEmail(email)) { - return 'invalid email'; - } - - if (!validateUsername(username)) { - return 'invalid username'; - } - - if (password.length < 8) { - return 'invalid password (Must be at least 8 characters long)'; - } - - if (password !== retype) { - return 'passwords do not match'; - } - - return null; -}; - -export default SignUp; diff --git a/client/components/panels/banned-emails.jsx b/client/components/panels/banned-emails.jsx deleted file mode 100644 index 0aab2c3..0000000 --- a/client/components/panels/banned-emails.jsx +++ /dev/null @@ -1,108 +0,0 @@ -import React, { useState, useEffect } from 'react'; - -const BannedEmails = props => { - const [data, setData] = useState(null); - let usernameElement, emailElement, expiryElement, reasonElement; - let unbanElement; - - fetch('/api/admin/banned', { method: 'GET' }) - .then(banned => banned.json()) - .then(banned => !data ? setData(banned) : null) - .catch(e => console.error(e)) - ; - - return ( -
-

Banned Accounts

- - - - - - - - - - - - {(data || []).map((entry, index) => - - - - - - - - )} - -
UsernameEmailPrivilegeExpiryReason
{entry.username}{entry.email}{entry.privilege}{entry.expiry ? (new Date(entry.expiry)).toISOString() : null}{entry.reason}
- -

Ban

-
{ e.preventDefault(); await handleBan(usernameElement.value, emailElement.value, expiryElement.value, reasonElement.value); }}> -
- - usernameElement = e} /> -
- -
- - emailElement = e} /> -
- -
- - expiryElement = e} /> -
- -
- -