diff --git a/.babelrc b/.babelrc index 318344bd28..8688cb63a3 100644 --- a/.babelrc +++ b/.babelrc @@ -11,5 +11,6 @@ "regenerator": true } ] - ] + ], + "sourceType": "unambiguous" } diff --git a/demo/User/User.validate.js b/demo/User/User.validate.js deleted file mode 100644 index 4c978b34e9..0000000000 --- a/demo/User/User.validate.js +++ /dev/null @@ -1,12 +0,0 @@ -const validate = require('express-validation'); -const Joi = require('joi'); - -// TODO: move field specific validations to the config -module.exports = { - post: validate({ - body: { - email: Joi.string().email().required(), - password: Joi.string().required(), - }, - }), -}; diff --git a/demo/collections/Page.js b/demo/collections/Page.js index 8f9519c81c..0bc07a5a6e 100644 --- a/demo/collections/Page.js +++ b/demo/collections/Page.js @@ -1,6 +1,5 @@ -import HttpStatus from 'http-status'; -import checkRoleMiddleware from '../../src/auth/checkRoleMiddleware'; - +const HttpStatus = require('http-status'); +const checkRoleMiddleware = require('../../src/auth/checkRoleMiddleware'); const Quote = require('../content-blocks/Quote'); const CallToAction = require('../content-blocks/CallToAction'); diff --git a/demo/collections/User.js b/demo/collections/User.js index 7fc17ad5b9..da864ce509 100644 --- a/demo/collections/User.js +++ b/demo/collections/User.js @@ -1,6 +1,4 @@ -const passportLocalMongoose = require('passport-local-mongoose'); const payloadConfig = require('../payload.config'); -const userValidate = require('../User/User.validate'); module.exports = { slug: 'users', @@ -34,9 +32,7 @@ module.exports = { strategy: 'jwt', passwordResets: true, registration: true, - registrationValidation: userValidate.post, }, - plugins: [{ plugin: passportLocalMongoose, options: { usernameField: 'email' } }], fields: [ { name: 'email', diff --git a/demo/payload.config.js b/demo/payload.config.js index 2dc2bfc85a..3ac63a6e5b 100644 --- a/demo/payload.config.js +++ b/demo/payload.config.js @@ -7,7 +7,7 @@ const Header = require('./globals/Header'); const Footer = require('./globals/Footer'); module.exports = { - disableAdmin: true, + // disableAdmin: true, collections: [Page, Category], user: User, upload: Upload, @@ -24,7 +24,7 @@ module.exports = { compression: {}, paths: { scssOverrides: path.resolve(__dirname, 'client/scss/overrides.scss'), - config: path.resolve(__dirname), + config: path.resolve(__dirname, 'payload.config.js'), }, mongoURL: 'mongodb://localhost/payload', localization: { diff --git a/package.json b/package.json index d5d2682c03..d3e0d196f6 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,10 @@ "superagent": "^3.8.3", "superagent-promise": "^1.1.0", "universal-cookie": "^3.1.0", - "url-loader": "^1.0.1" + "url-loader": "^1.0.1", + "webpack-dev-middleware": "^3.7.2", + "webpack-hot-middleware": "^2.25.0", + "webpack": "^4.41.0" }, "devDependencies": { "@babel/core": "^7.2.0", @@ -103,12 +106,6 @@ "sass-loader": "7.1.0", "style-loader": "^0.21.0", "supertest": "^3.4.2", - "uglifyjs-webpack-plugin": "^1.2.7", - "webpack": "^4.41.0", - "webpack-cli": "^3.3.9", - "webpack-dev-middleware": "^3.7.2", - "webpack-dev-server": "^3.8.1", - "webpack-hot-middleware": "^2.25.0", - "webpack-merge": "^4.2.2" + "uglifyjs-webpack-plugin": "^1.2.7" } } diff --git a/src/auth/checkRoleMiddleware.js b/src/auth/checkRoleMiddleware.js index 338cb7a855..4e93db433e 100644 --- a/src/auth/checkRoleMiddleware.js +++ b/src/auth/checkRoleMiddleware.js @@ -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; diff --git a/src/auth/routes.js b/src/auth/routes.js index a70e89e303..9c3252f720 100644 --- a/src/auth/routes.js +++ b/src/auth/routes.js @@ -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; diff --git a/src/client/components/index.js b/src/client/components/index.js index 5e3c5ef52b..1cd3c25fa2 100644 --- a/src/client/components/index.js +++ b/src/client/components/index.js @@ -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 = () => { - diff --git a/src/client/components/layout/Sidebar/index.js b/src/client/components/layout/Sidebar/index.js index 3cac190629..8e56082e97 100644 --- a/src/client/components/layout/Sidebar/index.js +++ b/src/client/components/layout/Sidebar/index.js @@ -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 ( ); -} +}; export default withRouter(connect(mapState)(Sidebar)); diff --git a/src/client/components/utilities/LoadConfig/index.js b/src/client/components/utilities/LoadConfig/index.js deleted file mode 100644 index 10408fdfa9..0000000000 --- a/src/client/components/utilities/LoadConfig/index.js +++ /dev/null @@ -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); diff --git a/src/client/components/views/Login/index.js b/src/client/components/views/Login/index.js index ae8486dbf7..3df8ec9fe0 100644 --- a/src/client/components/views/Login/index.js +++ b/src/client/components/views/Login/index.js @@ -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 ( - +
- - + redirect="/" + > + + Login To Dashboard diff --git a/src/client/config/getWebpackDevConfig.js b/src/client/config/getWebpackDevConfig.js index 8b5989352d..73fe05d160 100644 --- a/src/client/config/getWebpackDevConfig.js +++ b/src/client/config/getWebpackDevConfig.js @@ -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, }, }, }; diff --git a/src/collections/buildSchema.js b/src/collections/buildSchema.js index 9ebf1eaafe..e15ec16bb7 100644 --- a/src/collections/buildSchema.js +++ b/src/collections/buildSchema.js @@ -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; }; diff --git a/src/index.js b/src/index.js index 443e4a6460..1508339d59 100644 --- a/src/index.js +++ b/src/index.js @@ -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); diff --git a/src/init/webpack.js b/src/init/webpack.js index ea5972581a..eb737243f3 100644 --- a/src/init/webpack.js +++ b/src/init/webpack.js @@ -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;