Additional progress towards completion!
This commit is contained in:
parent
d622cb0589
commit
2eebc4f79e
16 changed files with 215 additions and 52 deletions
|
|
@ -6,7 +6,7 @@ import { registerPostHandler } from './app/controllers/registerPostHandler'
|
||||||
import { configGetHandler, configGetSpecificHandler } from './app/controllers/configGetHandler'
|
import { configGetHandler, configGetSpecificHandler } from './app/controllers/configGetHandler'
|
||||||
import { configPutHandler } from './app/controllers/configPutHandler'
|
import { configPutHandler } from './app/controllers/configPutHandler'
|
||||||
import { UserModel } from './app/db/user.schema'
|
import { UserModel } from './app/db/user.schema'
|
||||||
import { auth } from './app/middleware'
|
import { auth, optAuth } from './app/middleware'
|
||||||
|
|
||||||
interface AuthReq {
|
interface AuthReq {
|
||||||
user: UserModel | null
|
user: UserModel | null
|
||||||
|
|
@ -26,8 +26,8 @@ app.use(bodyParser.urlencoded({
|
||||||
extended: true
|
extended: true
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
app.put('/api/configs', optAuth, configPutHandler)
|
||||||
app.get('/api/configs', auth, configGetHandler)
|
app.get('/api/configs', auth, configGetHandler)
|
||||||
app.put('/api/configs', auth, configPutHandler)
|
|
||||||
app.get('/api/configs/:id', configGetSpecificHandler)
|
app.get('/api/configs/:id', configGetSpecificHandler)
|
||||||
app.post('/api/users/login', loginPostHandler)
|
app.post('/api/users/login', loginPostHandler)
|
||||||
app.post('/api/users/register', registerPostHandler)
|
app.post('/api/users/register', registerPostHandler)
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ export const configPutHandler = async (req: Request, res: Response) => {
|
||||||
config.json = req.body.json
|
config.json = req.body.json
|
||||||
await config.save()
|
await config.save()
|
||||||
|
|
||||||
req.user?.configs.push(config._id)
|
if(req.user) {
|
||||||
|
req.user.configs.push(config._id)
|
||||||
await req.user.save()
|
await req.user.save()
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).json(config.json)
|
return res.status(200).send(config._id)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex)
|
console.error(ex)
|
||||||
return res.status(500).send({ error: ex })
|
return res.status(500).send({ error: ex })
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,29 @@ import * as jwt from 'jsonwebtoken'
|
||||||
import UserSchema from './db/user.schema'
|
import UserSchema from './db/user.schema'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
|
export const optAuth = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const token = req.header('auth-token')
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { _id, expiresAt } = (jwt.verify(token, process.env.JWT_SECRET as string) as { _id: string, expiresAt: string })
|
||||||
|
|
||||||
|
if (moment(moment()).isAfter(expiresAt)) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await UserSchema.findById(_id)
|
||||||
|
req.user = user || null
|
||||||
|
|
||||||
|
return next()
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(400).send(`Invalid Token: ${err}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const auth = async (req: Request, res: Response, next: NextFunction) => {
|
export const auth = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const token = req.header('auth-token')
|
const token = req.header('auth-token')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
await mongoose.connect(`mongodb://${process.env.MONGO_URI}/Blog`, {
|
await mongoose.connect(`mongodb://${process.env.MONGO_URI}/GeolosysConfigGen`, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true
|
useUnifiedTopology: true
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { Provider } from 'react-redux';
|
||||||
import { BrowserRouter as Router, Route } from 'react-router-dom';
|
import { BrowserRouter as Router, Route } from 'react-router-dom';
|
||||||
import LoadAuth from './auth/load';
|
import LoadAuth from './auth/load';
|
||||||
import NavBar from './components/modules/NavBar';
|
import NavBar from './components/modules/NavBar';
|
||||||
|
import ConfigBrowse from './components/view/ConfigBrowse';
|
||||||
import ConfigCreate from './components/view/ConfigCreate';
|
import ConfigCreate from './components/view/ConfigCreate';
|
||||||
import Login from './components/view/Login';
|
import Login from './components/view/Login';
|
||||||
import Register from './components/view/Register';
|
import Register from './components/view/Register';
|
||||||
|
|
@ -20,6 +21,7 @@ export default () => {
|
||||||
<div style={{ paddingTop: `${3.5}em` }} />
|
<div style={{ paddingTop: `${3.5}em` }} />
|
||||||
<Route exact path="/" component={ConfigCreate} />
|
<Route exact path="/" component={ConfigCreate} />
|
||||||
<Route exact path="/login" component={Login} />
|
<Route exact path="/login" component={Login} />
|
||||||
|
<Route exact path="/browse" component={ConfigBrowse} />
|
||||||
<Route exact path="/register" component={Register} />
|
<Route exact path="/register" component={Register} />
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
|
|
|
||||||
4
frontend/src/axios/Config/GetConfig.js
Normal file
4
frontend/src/axios/Config/GetConfig.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default (id) => axios.get(`/api/configs/${id}`)
|
||||||
|
.then((resp) => resp.data);
|
||||||
7
frontend/src/axios/Config/GetConfigs.js
Normal file
7
frontend/src/axios/Config/GetConfigs.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
import store from '../../redux/store';
|
||||||
|
|
||||||
|
export default () => axios.get('/api/configs/')
|
||||||
|
.then((resp) => {
|
||||||
|
store.dispatch({ type: 'SET_CONFIGS', configs: resp.data || [] });
|
||||||
|
});
|
||||||
8
frontend/src/axios/Config/PutConfig.js
Normal file
8
frontend/src/axios/Config/PutConfig.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
import GetConfigs from './GetConfigs';
|
||||||
|
|
||||||
|
export default (data) => axios.put('/api/configs', data)
|
||||||
|
.then((resp) => {
|
||||||
|
GetConfigs();
|
||||||
|
return resp.data;
|
||||||
|
});
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
export default (data) => {
|
|
||||||
console.log(data);
|
|
||||||
axios.post('/api/configs', data);
|
|
||||||
};
|
|
||||||
|
|
@ -28,7 +28,7 @@ const NavBarComponent = ({
|
||||||
<NavLinkItem name="Create" dest="/" icon={faPlusSquare} />
|
<NavLinkItem name="Create" dest="/" icon={faPlusSquare} />
|
||||||
|
|
||||||
{store.getState().isAuthenticated && (
|
{store.getState().isAuthenticated && (
|
||||||
<NavLinkItem name="Your Configs" dest="/configs" icon={faCode} />
|
<NavLinkItem name="Your Configs" dest="/browse" icon={faCode} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{store.getState().isAuthenticated && (
|
{store.getState().isAuthenticated && (
|
||||||
|
|
|
||||||
64
frontend/src/components/view/ConfigBrowse.jsx
Normal file
64
frontend/src/components/view/ConfigBrowse.jsx
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { Table, Container } from 'react-bootstrap';
|
||||||
|
import { CSSTransition } from 'react-transition-group';
|
||||||
|
import GetConfigs from '../../axios/Config/GetConfigs';
|
||||||
|
|
||||||
|
const ConfigViewComponent = ({
|
||||||
|
configs,
|
||||||
|
}) => {
|
||||||
|
if (!Array.isArray(configs)) {
|
||||||
|
GetConfigs();
|
||||||
|
return (
|
||||||
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
|
<div className="v-center"><h1>Loading...</h1></div>
|
||||||
|
</CSSTransition>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configs.length) {
|
||||||
|
return (
|
||||||
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
|
<div className="v-center">
|
||||||
|
<h1>
|
||||||
|
No Configs Found
|
||||||
|
{' '}
|
||||||
|
<span role="img" aria-label="frown-emoji">🙁</span>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</CSSTransition>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-center mt-3">Your Configs</h2>
|
||||||
|
<Container className="perfect-width">
|
||||||
|
<Table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>URL</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{configs.map((slug, idx) => (
|
||||||
|
<tr>
|
||||||
|
<td>{idx + 1}</td>
|
||||||
|
<td><a href={`/?id=${slug}`}>{slug}</a></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</Table>
|
||||||
|
</Container>
|
||||||
|
</div>
|
||||||
|
</CSSTransition>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
configs: state.configs,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(ConfigViewComponent);
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Accordion, Container, Button } from 'react-bootstrap';
|
import { Accordion, Button, Container } from 'react-bootstrap';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { CSSTransition } from 'react-transition-group';
|
||||||
|
import PutConfig from '../../axios/Config/PutConfig';
|
||||||
|
import GetConfig from '../../axios/Config/GetConfig';
|
||||||
|
import ConfigRender from './ConfigRender';
|
||||||
import ConfigRenderOre from './ConfigRenderOre';
|
import ConfigRenderOre from './ConfigRenderOre';
|
||||||
import ConfigRenderStone from './ConfigRenderStone';
|
import ConfigRenderStone from './ConfigRenderStone';
|
||||||
import PostGenerateJson from '../../axios/Generate';
|
|
||||||
|
|
||||||
const Configurator = ({
|
const Configurator = ({
|
||||||
mc114,
|
mc114,
|
||||||
}) => {
|
}) => {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const [postRender, setPostRender] = useState(null);
|
||||||
|
|
||||||
const [oreConfigs, setOreConfigs] = useState([true]);
|
const [oreConfigs, setOreConfigs] = useState([true]);
|
||||||
const [stoneConfigs, setStoneConfigs] = useState([true]);
|
const [stoneConfigs, setStoneConfigs] = useState([true]);
|
||||||
const [oreState, setOreState] = useState([{
|
const [oreState, setOreState] = useState([{
|
||||||
|
|
@ -32,6 +38,21 @@ const Configurator = ({
|
||||||
dimBlacklist: [],
|
dimBlacklist: [],
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
if (params.has('id')) {
|
||||||
|
if (postRender) {
|
||||||
|
return (<ConfigRender jsonData={postRender} />);
|
||||||
|
}
|
||||||
|
|
||||||
|
GetConfig(params.get('id')).then((data) => (
|
||||||
|
setPostRender(data)
|
||||||
|
));
|
||||||
|
return (
|
||||||
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
|
<div className="v-center"><h1>Loading...</h1></div>
|
||||||
|
</CSSTransition>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const addOreEntry = () => {
|
const addOreEntry = () => {
|
||||||
setOreConfigs([...oreConfigs, true]);
|
setOreConfigs([...oreConfigs, true]);
|
||||||
};
|
};
|
||||||
|
|
@ -45,8 +66,6 @@ const Configurator = ({
|
||||||
const onOreConfigChange = (idx, oreConfigState) => {
|
const onOreConfigChange = (idx, oreConfigState) => {
|
||||||
const newState = [...oreState];
|
const newState = [...oreState];
|
||||||
newState[idx] = oreConfigState;
|
newState[idx] = oreConfigState;
|
||||||
console.log('Ore State Change', idx, oreConfigState);
|
|
||||||
console.log(newState);
|
|
||||||
setOreState(newState);
|
setOreState(newState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -63,12 +82,11 @@ const Configurator = ({
|
||||||
const onStoneConfigChange = (idx, stoneConfigState) => {
|
const onStoneConfigChange = (idx, stoneConfigState) => {
|
||||||
const newState = [...stoneState];
|
const newState = [...stoneState];
|
||||||
newState[idx] = stoneConfigState;
|
newState[idx] = stoneConfigState;
|
||||||
console.log('Stone State Change', idx, stoneConfigState);
|
|
||||||
console.log(newState);
|
|
||||||
setStoneState(newState);
|
setStoneState(newState);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||||
<div>
|
<div>
|
||||||
<div className="text-center d-block">
|
<div className="text-center d-block">
|
||||||
<img className="header" src={`${process.env.PUBLIC_URL}/logo.png`} alt="Geolosys Logo" />
|
<img className="header" src={`${process.env.PUBLIC_URL}/logo.png`} alt="Geolosys Logo" />
|
||||||
|
|
@ -106,15 +124,20 @@ const Configurator = ({
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => PostGenerateJson({
|
onClick={() => PutConfig({
|
||||||
|
json: {
|
||||||
ores: oreState,
|
ores: oreState,
|
||||||
stones: stoneState,
|
stones: stoneState,
|
||||||
|
},
|
||||||
|
}).then((data) => {
|
||||||
|
window.location.href = `/?id=${data}`;
|
||||||
})}
|
})}
|
||||||
className="d-block mx-auto my-4"
|
className="d-block mx-auto my-4"
|
||||||
>
|
>
|
||||||
Generate!
|
Generate!
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</CSSTransition>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
15
frontend/src/components/view/ConfigRender.jsx
Normal file
15
frontend/src/components/view/ConfigRender.jsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { Container } from 'react-bootstrap';
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
jsonData,
|
||||||
|
}) => (
|
||||||
|
<div>
|
||||||
|
<h2 className="text-center mt-3">Config View</h2>
|
||||||
|
<Container className="shadow mt-5">
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(jsonData.json, null, 2) }
|
||||||
|
</pre>
|
||||||
|
</Container>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
@ -19,7 +19,6 @@ export default ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const setStateWithPropogation = (newState) => {
|
const setStateWithPropogation = (newState) => {
|
||||||
console.log(newState);
|
|
||||||
setState(newState);
|
setState(newState);
|
||||||
onConfigChange(idx, newState);
|
onConfigChange(idx, newState);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,20 @@
|
||||||
|
@font-face {
|
||||||
|
font-family: 'JetBrainsMono';
|
||||||
|
src: url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2') format('woff2'), url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Regular.woff') format('woff'), url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/ttf/JetBrainsMono-Regular.ttf') format('truetype');
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
font-family: 'JetBrainsMono';
|
||||||
|
font-variant-ligatures: common-ligatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container.perfect-width {
|
||||||
|
max-width: 768px;
|
||||||
|
width: 98%;
|
||||||
|
}
|
||||||
|
|
||||||
.perfect-width {
|
.perfect-width {
|
||||||
max-width: 384px;
|
max-width: 384px;
|
||||||
width: 85%;
|
width: 85%;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ export default function reducer(
|
||||||
...state,
|
...state,
|
||||||
mc114: !state.mc114,
|
mc114: !state.mc114,
|
||||||
};
|
};
|
||||||
|
case 'SET_CONFIGS':
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
configs: action.configs,
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue