From 131416f65d702ff460676186582d2f6cdacd527d Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Tue, 30 Apr 2024 19:27:42 +1000 Subject: [PATCH] Added Raw code editor path for writing to database rawly main --- remix/app/Providers/Chakra/space.tsx | 12 +- remix/app/Providers/Chakra/theme.tsx | 137 +++++++++--------- ...{checkUserExists.ts => userCheckExists.ts} | 6 +- remix/app/api/utils/userValidatePassword.ts | 31 ++++ remix/app/components/Layout/Main.tsx | 33 +++-- remix/app/components/MongoDB/Raw.tsx | 28 ++++ .../app/components/Thingtime/ThingtimeURL.tsx | 25 +--- remix/app/routes/api/v1/login/_login.tsx | 43 ++++-- remix/app/routes/raw.tsx | 11 ++ remix/package.json | 2 + 10 files changed, 204 insertions(+), 124 deletions(-) rename remix/app/api/utils/{checkUserExists.ts => userCheckExists.ts} (64%) create mode 100644 remix/app/api/utils/userValidatePassword.ts create mode 100644 remix/app/components/MongoDB/Raw.tsx create mode 100644 remix/app/routes/raw.tsx diff --git a/remix/app/Providers/Chakra/space.tsx b/remix/app/Providers/Chakra/space.tsx index a9d106f..c74e26f 100644 --- a/remix/app/Providers/Chakra/space.tsx +++ b/remix/app/Providers/Chakra/space.tsx @@ -1,10 +1,12 @@ -const spaceObj = {} +const spaceObj = {}; -const start = 0 -const end = 9999 +const start = 0; +const end = 9999; for (let i = start; i <= end; i++) { - spaceObj[i] = `${i * 0.25}rem` + spaceObj[i] = `${i * 0.25}rem`; } -export const space = spaceObj +spaceObj['container'] = '700px'; + +export const space = spaceObj; diff --git a/remix/app/Providers/Chakra/theme.tsx b/remix/app/Providers/Chakra/theme.tsx index 55e7c21..057da69 100644 --- a/remix/app/Providers/Chakra/theme.tsx +++ b/remix/app/Providers/Chakra/theme.tsx @@ -6,58 +6,59 @@ import { NumberInputField, NumberInputStepper, Select, - Switch, -} from "@chakra-ui/react" + Switch +} from '@chakra-ui/react'; -import { colors } from "./colors" -import { space } from "./space" +import { colors } from './colors'; +import { space } from './space'; export const theme = extendTheme({ colors, // edit Input defaultProps space, + sizes: space, styles: { global: { // make all elements padding and margin animate - "*": { - transition: "padding 0.2s ease, margin 0.2s ease-out", + '*': { + transition: 'padding 0.2s ease, margin 0.2s ease-out' }, // make all elements have a transparent focus border - "input:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'input:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "textarea:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'textarea:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "select:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'select:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "button:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'button:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "div:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'div:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "a:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", + 'a:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' }, // make all elements have a transparent focus border - "span:focus": { - boxShadow: "none !important", - borderColor: "transparent !important", - }, - }, + 'span:focus': { + boxShadow: 'none !important', + borderColor: 'transparent !important' + } + } }, components: { Input: { @@ -70,8 +71,8 @@ export const theme = extendTheme({ // "padding-inline-start": "0px", field: { // "padding-inline-start": "0px", - }, - }, + } + } }, Select: { baseStyle: { @@ -80,73 +81,73 @@ export const theme = extendTheme({ }, icon: { // height: "8px", - width: "14px", - }, - }, + width: '14px' + } + } }, Switch: { baseStyle: { track: { - background: "grays.medium", + background: 'grays.medium', _checked: { - background: "chakras.throat", - }, - }, - }, + background: 'chakras.throat' + } + } + } }, NumberInput: { baseStyle: { field: { - width: "auto", + width: 'auto' // border: "none", - }, - }, - }, - }, -}) + } + } + } + } +}); Switch.defaultProps = { ...Switch.defaultProps, - as: "div", -} + as: 'div' +}; Select.defaultProps = { ...Select.defaultProps, - focusBorderColor: "transparent", - outline: "0px solid", - border: "none", - ps: "0px", - px: "0px", + focusBorderColor: 'transparent', + outline: '0px solid', + border: 'none', + ps: '0px', + px: '0px', sx: { - paddingInlineStart: "0px", - paddingInlineEnd: "24px", - }, -} + paddingInlineStart: '0px', + paddingInlineEnd: '24px' + } +}; NumberInput.defaultProps = { ...NumberInput.defaultProps, - variant: "unstyled", -} + variant: 'unstyled' +}; NumberInputField.defaultProps = { ...NumberInputField.defaultProps, - height: "100%", + height: '100%', pr: 3, - fontSize: "inherit", + fontSize: 'inherit' // variant: "unstyled", -} +}; NumberInputStepper.defaultProps = { ...NumberInputStepper.defaultProps, - border: "none", - color: "grays.medium", -} + border: 'none', + color: 'grays.medium' +}; NumberIncrementStepper.defaultProps = { ...NumberIncrementStepper.defaultProps, - border: "none", -} + border: 'none' +}; NumberDecrementStepper.defaultProps = { ...NumberDecrementStepper.defaultProps, - border: "none", -} + border: 'none' +}; diff --git a/remix/app/api/utils/checkUserExists.ts b/remix/app/api/utils/userCheckExists.ts similarity index 64% rename from remix/app/api/utils/checkUserExists.ts rename to remix/app/api/utils/userCheckExists.ts index 95b526e..f30dc13 100644 --- a/remix/app/api/utils/checkUserExists.ts +++ b/remix/app/api/utils/userCheckExists.ts @@ -1,15 +1,15 @@ -// query mongodb for user objects with the email provided +// query mongodb for user objects with the username provided // if user exists, return true // if user does not exist, return false import { createConnection } from './mongodb/connection'; -export const checkUserExists = async ({ email }) => { +export const userCheckExists = async ({ username }) => { const client = await createConnection(); const db = client.db('auth'); const collection = db.collection('users'); - const user = await collection.findOne({ email }); + const user = await collection.findOne({ username }); if (user) { return true; diff --git a/remix/app/api/utils/userValidatePassword.ts b/remix/app/api/utils/userValidatePassword.ts new file mode 100644 index 0000000..392fbbd --- /dev/null +++ b/remix/app/api/utils/userValidatePassword.ts @@ -0,0 +1,31 @@ +// query mongodb for user objects with the username provided +// if user exists, return true +// if user does not exist, return false + +import { createConnection } from './mongodb/connection'; + +import bcrypt from 'bcrypt'; + +export const userValidatePassword = async ({ username, password }) => { + + const client = await createConnection(); + const db = client.db('auth'); + const collection = db.collection('users'); + const user = await collection.findOne({ username }); + + if (!user) { + return false; + } + + const { password: hash } = user; + + const match = await bcrypt.compare(password, hash); + + if (match) { + return true; + } + + return false; + +} + \ No newline at end of file diff --git a/remix/app/components/Layout/Main.tsx b/remix/app/components/Layout/Main.tsx index 3ae5406..ccf5853 100644 --- a/remix/app/components/Layout/Main.tsx +++ b/remix/app/components/Layout/Main.tsx @@ -1,30 +1,41 @@ -import { Box, Flex } from "@chakra-ui/react" +import { Box, Flex } from '@chakra-ui/react'; -import { Footer } from "../Nav/Footer" -import { Nav } from "../Nav/Nav" -import { ProfileDrawer } from "../Nav/ProfileDrawer" +import { Footer } from '../Nav/Footer'; +import { Nav } from '../Nav/Nav'; +import { ProfileDrawer } from '../Nav/ProfileDrawer'; export const Main = (props) => { return ( {/* */}