save project without logging in

This commit is contained in:
catarak 2016-06-20 13:46:01 -04:00
parent 44b41072c1
commit d8f47d714b
2 changed files with 18 additions and 21 deletions

View File

@ -1,28 +1,24 @@
import Project from '../models/project'
export function createProject(req, res) {
if (req.user) {
Project.create({
user: req.user._id,
name: req.body.name,
Project.create({
user: req.user ? req.user._id : undefined,
name: req.body.name,
file: {
name: req.body.file.name,
content: req.body.file.content
}
}, function(err, newProject) {
if (err) { return res.json({success: false}); }
return res.json({
id: newProject._id,
name: newProject.name,
file: {
name: req.body.file.name,
content: req.body.file.content
name: newProject.file.name,
content: newProject.file.content
}
}, function(err, newProject) {
if (err) { return res.json({success: false}) }
return res.json({
id: newProject._id,
name: newProject.name,
file: {
name: newProject.file.name,
content: newProject.file.content
}
});
});
} else {
res.json({success: false});
}
});
});
}
export function updateProject(req, res) {

View File

@ -1,4 +1,5 @@
import * as ActionTypes from '../constants/constants'
import { browserHistory } from 'react-router'
import axios from 'axios'
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@ -54,7 +55,7 @@ export function saveProject() {
else {
axios.post(`${ROOT_URL}/projects`, formParams, {withCredentials: true})
.then(response => {
browserHistory.push('/' + response.data.id);
browserHistory.push('/projects/' + response.data.id);
dispatch({
type: ActionTypes.NEW_PROJECT,
name: response.data.name,