sign up view renders, not tested if functional
This commit is contained in:
parent
c22ae1724a
commit
4e1ea2d1fc
6 changed files with 61 additions and 6 deletions
|
@ -0,0 +1,33 @@
|
||||||
|
import User from '../models/user'
|
||||||
|
import passport from 'passport'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
|
export function newUser(req, res) {
|
||||||
|
//eventually, it would be cool to have some isomorphic rendering
|
||||||
|
res.sendFile(path.resolve(__dirname + '/../../index.html'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createUser(req, res, next) {
|
||||||
|
const user = new User({
|
||||||
|
email: req.body.email,
|
||||||
|
password: req.body.password
|
||||||
|
});
|
||||||
|
|
||||||
|
User.findOne({email: req.body.email}, (err, existingUser) => {
|
||||||
|
if (existingUser) {
|
||||||
|
//error, already registered
|
||||||
|
//should probably redirect client side though?
|
||||||
|
return res.redirect('/signup');
|
||||||
|
}
|
||||||
|
user.save((err) => {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
req.logIn(user, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
res.redirect('/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
|
@ -2,11 +2,11 @@ import mongoose from 'mongoose';
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
const userSchema = new Schema({
|
const userSchema = new Schema({
|
||||||
name: { type: 'String' },
|
name: { type: String, default: '' },
|
||||||
username: { type: 'String', required: true, unique: true},
|
username: { type: String, required: true, unique: true},
|
||||||
password: { type: 'String' },
|
password: { type: String },
|
||||||
github: { type: 'String' },
|
github: { type: String },
|
||||||
email: { type: 'String', unique: true },
|
email: { type: String, unique: true },
|
||||||
tokens: Array,
|
tokens: Array,
|
||||||
admin: { type: Boolean, default: false }
|
admin: { type: Boolean, default: false }
|
||||||
}, {timestamps: true});
|
}, {timestamps: true});
|
||||||
|
|
|
@ -5,3 +5,5 @@ const router = new Router();
|
||||||
router.route('/signup').get(UserController.newUser);
|
router.route('/signup').get(UserController.newUser);
|
||||||
|
|
||||||
router.route('/signup').post(UserController.createUser);
|
router.route('/signup').post(UserController.createUser);
|
||||||
|
|
||||||
|
export default router;
|
|
@ -21,6 +21,7 @@ app.use(webpackHotMiddleware(compiler));
|
||||||
|
|
||||||
//Import all required modules
|
//Import all required modules
|
||||||
import serverConfig from './config';
|
import serverConfig from './config';
|
||||||
|
import users from './routes/user.routes';
|
||||||
|
|
||||||
//Body parser, cookie parser, sessions, serve public assets
|
//Body parser, cookie parser, sessions, serve public assets
|
||||||
const MongoStore = require('connect-mongo')(session);
|
const MongoStore = require('connect-mongo')(session);
|
||||||
|
@ -43,6 +44,7 @@ app.use(session({
|
||||||
}));
|
}));
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
app.use(passport.session());
|
app.use(passport.session());
|
||||||
|
app.use('/', users);
|
||||||
|
|
||||||
const passportConfig = require('./config/passport');
|
const passportConfig = require('./config/passport');
|
||||||
|
|
||||||
|
|
16
shared/containers/SignupView/SignupView.jsx
Normal file
16
shared/containers/SignupView/SignupView.jsx
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
class SignupView extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<form>
|
||||||
|
<input type="text" placeholder="Username"/>
|
||||||
|
<input type="text" placeholder="Email"/>
|
||||||
|
<input type="password" placeholder="Password"/>
|
||||||
|
<input type="submit" value="Sign Up" />
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SignupView;
|
|
@ -3,11 +3,13 @@ import React from 'react'
|
||||||
import App from './containers/App'
|
import App from './containers/App'
|
||||||
import IDEView from './containers/IDEView/IDEView'
|
import IDEView from './containers/IDEView/IDEView'
|
||||||
import LoginView from './containers/LoginView/LoginView'
|
import LoginView from './containers/LoginView/LoginView'
|
||||||
|
import SignupView from './containers/SignupView/SignupView'
|
||||||
|
|
||||||
const routes = (
|
const routes = (
|
||||||
<Route path="/" component={App}>
|
<Route path="/" component={App}>
|
||||||
<IndexRoute component={IDEView} />
|
<IndexRoute component={IDEView} />
|
||||||
<Route path="/login" component={LoginView}/>
|
<Route path="/login" component={LoginView}/>
|
||||||
|
<Route path="/signup" component={SignupView}/>
|
||||||
</Route>
|
</Route>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue