enables loading config within webpack
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import HttpStatus from 'http-status';
|
||||
const HttpStatus = require('http-status');
|
||||
|
||||
/**
|
||||
* authorize a request by comparing the current user with one or more roles
|
||||
* @param roles
|
||||
* @returns {Function}
|
||||
*/
|
||||
export default function checkRoleMiddleware(...roles) {
|
||||
|
||||
const checkRoleMiddleware = (...roles) => {
|
||||
return (req, res, next) => {
|
||||
if (!req.user) {
|
||||
res.status(HttpStatus.UNAUTHORIZED)
|
||||
@@ -17,4 +18,6 @@ export default function checkRoleMiddleware(...roles) {
|
||||
next();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = checkRoleMiddleware;
|
||||
|
||||
@@ -30,19 +30,17 @@ const authRoutes = (userConfig, User) => {
|
||||
if (userConfig.auth.registration) {
|
||||
router
|
||||
.route(`${userConfig.slug}/register`) // TODO: not sure how to incorporate url params like `:pageId`
|
||||
.post(userConfig.auth.registrationValidation, auth.register);
|
||||
.post(auth.register);
|
||||
|
||||
router
|
||||
.route('/first-register')
|
||||
.post(userConfig.auth.registrationValidation,
|
||||
(req, res, next) => {
|
||||
User.countDocuments({}, (err, count) => {
|
||||
if (err) res.status(500).json({ error: err });
|
||||
if (count >= 1) return res.status(403).json({ initialized: true });
|
||||
next();
|
||||
});
|
||||
},
|
||||
auth.register);
|
||||
.post((req, res, next) => {
|
||||
User.countDocuments({}, (err, count) => {
|
||||
if (err) res.status(500).json({ error: err });
|
||||
if (count >= 1) return res.status(403).json({ initialized: true });
|
||||
next();
|
||||
});
|
||||
}, auth.register);
|
||||
}
|
||||
|
||||
return router;
|
||||
|
||||
@@ -4,7 +4,6 @@ import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import Routes from './routes';
|
||||
import store from '../store';
|
||||
import LoadConfig from './utilities/LoadConfig';
|
||||
import MeasureWindow from './utilities/MeasureWindow';
|
||||
import MeasureScroll from './utilities/MeasureScroll';
|
||||
import SetLocale from './utilities/SetLocale';
|
||||
@@ -19,7 +18,6 @@ const Index = () => {
|
||||
<Fragment>
|
||||
<MeasureScroll />
|
||||
<MeasureWindow />
|
||||
<LoadConfig />
|
||||
<SetLocale />
|
||||
<SetSearchParams />
|
||||
<Routes />
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { withRouter, NavLink, Link } from 'react-router-dom';
|
||||
import { connect } from 'react-redux';
|
||||
import { NavLink, Link } from 'react-router-dom';
|
||||
import config from 'payload-config';
|
||||
|
||||
import Arrow from '../../graphics/Arrow';
|
||||
import Icon from '../../graphics/Icon';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const mapState = state => ({
|
||||
config: state.common.config
|
||||
config: state.common.config,
|
||||
});
|
||||
|
||||
const Sidebar = props => {
|
||||
|
||||
const Sidebar = (props) => {
|
||||
const {
|
||||
collections,
|
||||
routes: {
|
||||
admin,
|
||||
}
|
||||
} = props.config;
|
||||
},
|
||||
} = config;
|
||||
|
||||
return (
|
||||
<aside className="sidebar">
|
||||
@@ -34,7 +34,11 @@ const Sidebar = props => {
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<Link className={classes} key={i} to={href}>
|
||||
<Link
|
||||
className={classes}
|
||||
key={i}
|
||||
to={href}
|
||||
>
|
||||
<Arrow />
|
||||
{collections[key].labels.plural}
|
||||
</Link>
|
||||
@@ -43,21 +47,30 @@ const Sidebar = props => {
|
||||
</nav>
|
||||
<span className="uppercase-label">Globals</span>
|
||||
<nav>
|
||||
<NavLink activeClassName="active" to="/media-library">
|
||||
<NavLink
|
||||
activeClassName="active"
|
||||
to="/media-library"
|
||||
>
|
||||
<Arrow />
|
||||
Media Library
|
||||
</NavLink>
|
||||
<NavLink activeClassName="active" to="/components">
|
||||
<NavLink
|
||||
activeClassName="active"
|
||||
to="/components"
|
||||
>
|
||||
<Arrow />
|
||||
Components
|
||||
</NavLink>
|
||||
<NavLink activeClassName="active" to="/settings">
|
||||
<NavLink
|
||||
activeClassName="active"
|
||||
to="/settings"
|
||||
>
|
||||
<Arrow />
|
||||
Settings
|
||||
</NavLink>
|
||||
</nav>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default withRouter(connect(mapState)(Sidebar));
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import api from '../../../api';
|
||||
|
||||
const mapDispatch = dispatch => ({
|
||||
loadConfig: payload => dispatch({ type: 'LOAD_CONFIG', payload })
|
||||
})
|
||||
|
||||
class LoadConfig extends Component {
|
||||
componentDidMount() {
|
||||
api.requests.get('/config').then((config) => {
|
||||
this.props.loadConfig(config)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatch)(LoadConfig);
|
||||
@@ -11,30 +11,43 @@ import FormSubmit from '../../forms/Submit';
|
||||
import './index.scss';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
windowHeight: state.common.windowHeight
|
||||
windowHeight: state.common.windowHeight,
|
||||
});
|
||||
|
||||
const cookies = new Cookies();
|
||||
|
||||
const handleAjaxResponse = res => {
|
||||
const handleAjaxResponse = (res) => {
|
||||
cookies.set('token', res.token, { path: '/' });
|
||||
};
|
||||
|
||||
const Login = props => {
|
||||
|
||||
const Login = (props) => {
|
||||
const Logo = props.logo;
|
||||
const minHeight = props.windowHeight;
|
||||
|
||||
return (
|
||||
<ContentBlock className="login" width="narrow" style={{ minHeight }}>
|
||||
<ContentBlock
|
||||
className="login"
|
||||
width="narrow"
|
||||
style={{ minHeight }}
|
||||
>
|
||||
<div className="wrap">
|
||||
<Form
|
||||
handleAjaxResponse={handleAjaxResponse}
|
||||
method="POST"
|
||||
action="http://localhost:3000/login"
|
||||
redirect="/">
|
||||
<Email label="Email Address" name="email" required />
|
||||
<Password error="password" label="Password" name="password" required />
|
||||
redirect="/"
|
||||
>
|
||||
<Email
|
||||
label="Email Address"
|
||||
name="email"
|
||||
required
|
||||
/>
|
||||
<Password
|
||||
error="password"
|
||||
label="Password"
|
||||
name="password"
|
||||
required
|
||||
/>
|
||||
<FormSubmit>Login</FormSubmit>
|
||||
</Form>
|
||||
<Link to="/">To Dashboard</Link>
|
||||
|
||||
@@ -115,7 +115,7 @@ module.exports = (config) => {
|
||||
alias: {
|
||||
payload: path.resolve(__dirname, '../../'),
|
||||
scssOverrides: config.paths.scssOverrides,
|
||||
config: config.paths.config,
|
||||
'payload-config': config.paths.config,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,12 +14,6 @@ const buildCollectionSchema = (collection, config, schemaOptions = {}) => {
|
||||
.plugin(autopopulate)
|
||||
.plugin(mongooseHidden());
|
||||
|
||||
if (collection.plugins) {
|
||||
collection.plugins.forEach((plugin) => {
|
||||
schema.plugin(plugin.plugin, plugin.options);
|
||||
});
|
||||
}
|
||||
|
||||
return schema;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import mongoose from 'mongoose';
|
||||
import passportLocalMongoose from 'passport-local-mongoose';
|
||||
import connectMongoose from './init/connectMongoose';
|
||||
import registerExpressMiddleware from './init/registerExpressMiddleware';
|
||||
import initPassport from './init/passport';
|
||||
@@ -61,6 +62,7 @@ class Payload {
|
||||
registerUser = () => {
|
||||
this.config.user.fields.push(...baseUserFields);
|
||||
const userSchema = buildCollectionSchema(this.config.user, this.config);
|
||||
userSchema.plugin(passportLocalMongoose, { usernameField: 'email' });
|
||||
|
||||
this.User = mongoose.model(this.config.user.labels.singular, userSchema);
|
||||
initUserAuth(this.User, this.config, this.router);
|
||||
|
||||
@@ -18,13 +18,13 @@ const initWebpack = ({ config, app }) => {
|
||||
const filename = path.resolve(compiler.outputPath, 'index.html');
|
||||
compiler.outputFileSystem.readFile(filename, (err, result) => {
|
||||
if (err) {
|
||||
return next(err)
|
||||
return next(err);
|
||||
}
|
||||
res.set('content-type', 'text/html')
|
||||
res.send(result)
|
||||
res.end()
|
||||
})
|
||||
})
|
||||
}
|
||||
res.set('content-type', 'text/html');
|
||||
res.send(result);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default initWebpack;
|
||||
|
||||
Reference in New Issue
Block a user