add session and cookie and passport config for server

This commit is contained in:
catarak 2016-05-13 16:04:16 -04:00
parent 7cc1efcd94
commit 65c02922c7
3 changed files with 26 additions and 0 deletions

View file

@ -34,9 +34,12 @@
},
"dependencies": {
"babel-core": "^6.8.0",
"body-parser": "^1.15.1",
"classnames": "^2.2.5",
"codemirror": "^5.14.2",
"cookie-parser": "^1.4.1",
"express": "^4.13.4",
"mongoose": "^4.4.16",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-inlinesvg": "^0.4.2",

11
server/models/user.js Normal file
View file

@ -0,0 +1,11 @@
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const userSchema = new Schema({
name: { type: 'String' },
username: { type: 'String', required: true, unique: true},
password: { type: 'String' },
admin: { type: Boolean, default: false }
});
export default mongoose.model('User', userSchema);

View file

@ -1,4 +1,9 @@
import Express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import session from 'express-session';
import passport from 'passport';
import path from 'path';
//Webpack Requirements
@ -17,6 +22,13 @@ app.use(webpackHotMiddleware(compiler));
//Import all required modules
import serverConfig from './config';
//Body parser, cookie parser, sessions, serve public assets
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({secret: 'steve brule'}));
app.use(passport.initialize());
app.use(passport.session());
app.use(Express.static(path.resolve(__dirname, '../static')));
app.get("/", function(req, res) {