Skip to content

Commit a78619f

Browse files
committed
Merge branch 'master' into reusable
2 parents 8911e4c + fd328bf commit a78619f

22 files changed

+448
-175
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"electron-splashscreen": "^1.0.0",
139139
"enzyme": "^3.4.1",
140140
"enzyme-adapter-react-16": "^1.2.0",
141+
"formik": "^2.1.4",
141142
"js-cookie": "^2.2.1",
142143
"konva": "^4.2.0",
143144
"localforage": "^1.7.2",

server/controllers/projectController.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ projectController.saveProject = (req, res, next) => {
1414
{ name, userId },
1515
// update or insert the project
1616
{ project },
17-
// Options: upsert: true - if none found, inserts new project, if found, updates project
17+
// Options:
18+
// upsert: true - if none found, inserts new project, if found, updates project
1819
// new: true - returns updated document not the original one
1920
{ upsert: true, new: true },
2021
(err, result) => {
@@ -39,7 +40,7 @@ projectController.saveProject = (req, res, next) => {
3940
projectController.getProjects = (req, res, next) => {
4041
console.log('Inside projectController.getProjects...');
4142
const userId = req.cookies.ssid;
42-
Projects.find({ userId }, (err, projects) => {
43+
Projects.findOne({ userId }, (err, project) => {
4344
if (err) {
4445
return next({
4546
log: `Error in projectController.getProjects: ${err}`,
@@ -49,7 +50,7 @@ projectController.getProjects = (req, res, next) => {
4950
});
5051
} else {
5152
console.log('Successful getProjects');
52-
res.locals.projects = projects;
53+
res.locals.project = project;
5354
return next();
5455
}
5556
});

server/controllers/sessionController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sessionController.isLoggedIn = (req, res, next) => {
1717
// no session found, redirect to signup page
1818
} else if (!session) {
1919
console.log('No session found, redirecting to signup page');
20-
return res.redirect('/signup');
20+
return res.redirect('/');
2121
} else {
2222
// session found, move onto next middleware
2323
console.log('Session found, moving onto next middleware');

server/controllers/userController.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ userController.createUser = (req, res, next) => {
2323
// create user using username and password
2424
Users.create({ username, password, email }, (err, newUser) => {
2525
if (err) {
26+
if(err.keyValue.email) {
27+
return res.status(400).json('Email Taken');
28+
}
29+
if(err.keyValue.username) {
30+
return res.status(400).json('Username Taken');
31+
}
2632
return next({
2733
log: `Error in userController.createUser: ${err}`,
2834
message: {
2935
err: `Error in userController.createUser. Check server logs for details`
30-
}
31-
});
36+
}});
3237
} else {
3338
// this id property will be used in other middleware for cookie
3439
console.log('Successful createUser');
@@ -45,10 +50,10 @@ userController.verifyUser = (req, res, next) => {
4550
console.log('Inside userController.verifyUser...');
4651
const { username, password } = req.body;
4752
if (!username) {
48-
return res.status(400).json('No username input');
53+
return res.status(400).json('No Username Input');
4954
}
5055
if (!password) {
51-
return res.status(400).json('No password input');
56+
return res.status(400).json('No Password Input');
5257
}
5358
Users.findOne({ username }, (err, user) => {
5459
if (err) {
@@ -68,11 +73,11 @@ userController.verifyUser = (req, res, next) => {
6873
return next();
6974
} else {
7075
// if password does not match, redirect to ?
71-
return res.status(400).json('Incorrect password');
76+
return res.status(400).json('Incorrect Password');
7277
}
7378
});
7479
} else {
75-
return res.status(400).json('No such user found');
80+
return res.status(400).json('Invalid Username');
7681
}
7782
});
7883
};

server/models/reactypeModels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const sessionSchema = new Schema({
5252
});
5353

5454
const projectSchema = new Schema({
55-
name: { type: String, required: true },
56-
project: Object,
55+
name: String,
56+
project: { type: Object, required: true },
5757
userId: {
5858
type: Schema.Types.ObjectId,
5959
ref: 'Users'

server/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ app.use(cookieParser());
3838

3939
// statically serve everything in build folder
4040
app.use('/', express.static(path.resolve(__dirname, '../build')));
41+
// statically serve images
4142
app.use(
4243
'/images',
4344
express.static(path.resolve(__dirname, '..src/public/images'))
4445
);
4546

47+
// serves main app, we are going to serve main app to electron locally, this will be deprecated
48+
// this backend server will only be used for authentication and project management services
4649
app.get('/', (req, res) => {
4750
res.status(200).sendFile(path.resolve(__dirname, '../build/index.html'));
4851
});
@@ -81,7 +84,7 @@ app.get(
8184
sessionController.isLoggedIn,
8285
projectController.getProjects,
8386
(req, res) => {
84-
return res.status(200).json(res.locals.projects);
87+
return res.status(200).json(res.locals.project);
8588
}
8689
);
8790

src/components/AppNew.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useReducer } from 'react';
1+
import React, { useState, useReducer, useEffect } from 'react';
22
import '../public/styles/style.css';
33
import '../public/styles/styleNew.css';
44
import { DndProvider } from 'react-dnd';
@@ -7,12 +7,41 @@ import AppContainer from '../containers/AppContainer';
77
import { stateContext } from '../context/context';
88
import initialState from '../context/initialState';
99
import reducer from '../reducers/componentReducerNew';
10+
import { getProjects } from '../helperFunctions/projectGetSave';
11+
import { saveProject } from '../helperFunctions/projectGetSave';
12+
import { loadInitData } from '../actions/actionCreators';
1013
// import { Context, State } from '../interfaces/InterfacesNew';
1114

1215
// Intermediary component to wrap main App component with higher order provider components
1316
export const App = (): JSX.Element => {
1417
// const [context, setContext] = useState(initialState);
18+
//let initialStateLoaded = false;
19+
// retrieves user's project (if it exists) from DB on component load
1520
const [state, dispatch] = useReducer(reducer, initialState);
21+
22+
// gets projects from DB for current user on mount
23+
useEffect(() => {
24+
// getProjects returns a promise which is thenable
25+
getProjects().then(project => {
26+
if (project) {
27+
// if user has project we run a dispatch to update state with received project
28+
dispatch({
29+
type: 'SET INITIAL STATE',
30+
payload: project
31+
});
32+
}
33+
});
34+
}, []);
35+
36+
// saves project to DB whenever there are changes to the state via this canvas component
37+
useEffect(() => {
38+
console.log('useEffect in CanvasNew ran');
39+
// setTimeout is necessary so the saveProjects method does not fire and save an empty project before the initial getProjects in AppNew
40+
setTimeout(() => {
41+
saveProject(state);
42+
}, 1000);
43+
}, [state]);
44+
1645
return (
1746
<div className="app">
1847
<DndProvider backend={HTML5Backend}>

src/components/left/ComponentPanelNew.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const useStyles = makeStyles({
2020
height: '110px',
2121
textAlign: 'center',
2222
display: 'flex',
23-
justifyContent: 'flex-end'
23+
justifyContent: 'center',
24+
paddingLeft: '35px'
2425
},
2526
panelWrapper: {
2627
marginTop: '35px',
@@ -30,7 +31,8 @@ const useStyles = makeStyles({
3031
maxHeight: '675px',
3132
minHeight: '120px',
3233
overflowY: 'auto',
33-
marginLeft: '-15px'
34+
marginLeft: '-15px',
35+
marginRight: '-15px'
3436
},
3537
input: {
3638
color: '#fff',

src/components/login/SignIn.tsx

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ import Checkbox from '@material-ui/core/Checkbox';
1919
import Link from '@material-ui/core/Link';
2020
import Grid from '@material-ui/core/Grid';
2121
import Box from '@material-ui/core/Box';
22-
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
2322
import Typography from '@material-ui/core/Typography';
2423
import { makeStyles, withStyles } from '@material-ui/core/styles';
2524
import Container from '@material-ui/core/Container';
25+
import GitHubIcon from '@material-ui/icons/GitHub';
26+
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
2627

2728
function Copyright() {
2829
return (
2930
<Typography variant="body2" color="textSecondary" align="center">
30-
{'Copyright © '}
31-
<Link color="inherit" href="https://material-ui.com/">
31+
{'Copyright © ReacType '}
32+
{/* <Link color="inherit" href="https://reactype.io/#fullCarousel">
3233
ReacType
33-
</Link>{' '}
34+
</Link>{' '} */}
3435
{new Date().getFullYear()}
3536
{'.'}
3637
</Typography>
@@ -42,20 +43,31 @@ const useStyles = makeStyles(theme => ({
4243
marginTop: theme.spacing(8),
4344
display: 'flex',
4445
flexDirection: 'column',
45-
alignItems: 'center'
46+
alignItems: 'center',
4647
},
4748
avatar: {
4849
margin: theme.spacing(1),
49-
backgroundColor: theme.palette.secondary.main
50+
backgroundColor: '#3EC1AC'
5051
},
5152
form: {
5253
width: '100%', // Fix IE 11 issue.
5354
marginTop: theme.spacing(1)
5455
},
5556
submit: {
56-
margin: theme.spacing(3, 0, 2),
57-
width: '240px',
58-
height: '60px'
57+
margin: theme.spacing(1, 0, 2),
58+
// width: '240px',
59+
// height: '60px'
60+
},
61+
root: {
62+
// "& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
63+
// borderColor: "green"
64+
// },
65+
// "&:hover .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
66+
// borderColor: "red"
67+
// },
68+
"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline": {
69+
borderColor: "#3EC1AC"
70+
}
5971
}
6072
}));
6173

@@ -67,6 +79,11 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
6779
const [username, setUsername] = useState('');
6880
const [password, setPassword] = useState('');
6981

82+
const [invalidUserMsg, setInvalidUserMsg] = useState('');
83+
const [invalidPassMsg, setInvalidPassMsg] = useState('');
84+
const [invalidUser, setInvalidUser] = useState(false);
85+
const [invalidPass, setInvalidPass] = useState(false);
86+
7087
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
7188
let inputVal = e.target.value;
7289
switch (e.target.name) {
@@ -79,16 +96,47 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
7996
}
8097
};
8198

99+
/*
100+
Response Options:
101+
Success
102+
Error
103+
No Username Input
104+
No Password Input
105+
Incorrect Password
106+
Invalid Username
107+
*/
82108
const handleLogin = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
83109
e.preventDefault();
84110
console.log('click fired on handleLogin');
85-
sessionIsCreated(username, password).then(isLoggedIn => {
86-
if (isLoggedIn) {
87-
console.log('session created');
111+
112+
setInvalidUser(false);
113+
setInvalidUserMsg('');
114+
setInvalidPass(false);
115+
setInvalidPassMsg('');
116+
sessionIsCreated(username, password).then(loginStatus => {
117+
console.log('login fetch', loginStatus)
118+
if(loginStatus === 'Success') {
88119
dispatch(setLoginState()); // changes login state to true
89120
props.history.push('/');
90121
} else {
91-
console.log('invalid login');
122+
switch(loginStatus) {
123+
case 'No Username Input':
124+
setInvalidUser(true);
125+
setInvalidUserMsg(loginStatus);
126+
break;
127+
case 'No Password Input':
128+
setInvalidPass(true);
129+
setInvalidPassMsg(loginStatus);
130+
break;
131+
case 'Invalid Username':
132+
setInvalidUser(true);
133+
setInvalidUserMsg(loginStatus);
134+
break;
135+
case 'Incorrect Password':
136+
setInvalidPass(true);
137+
setInvalidPassMsg(loginStatus);
138+
break;
139+
}
92140
}
93141
});
94142
};
@@ -98,12 +146,13 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
98146
<CssBaseline />
99147
<div className={classes.paper}>
100148
<Avatar className={classes.avatar}>
101-
<LockOutlinedIcon />
149+
<LockOutlinedIcon/>
102150
</Avatar>
103-
<Typography component="h1" variant="h5">
151+
<Typography component="h1" variant="h5" color="textPrimary">
104152
Sign in
105153
</Typography>
106154
<TextField
155+
className={classes.root}
107156
variant="outlined"
108157
margin="normal"
109158
required
@@ -115,8 +164,11 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
115164
autoFocus
116165
value={username}
117166
onChange={handleChange}
167+
helperText={invalidUserMsg}
168+
error={invalidUser}
118169
/>
119170
<TextField
171+
className={classes.root}
120172
variant="outlined"
121173
margin="normal"
122174
required
@@ -128,6 +180,8 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
128180
autoComplete="current-password"
129181
value={password}
130182
onChange={handleChange}
183+
helperText={invalidPassMsg}
184+
error={invalidPass}
131185
/>
132186
<FormControlLabel
133187
control={<Checkbox value="remember" color="primary" />}
@@ -137,22 +191,33 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
137191
<Button
138192
fullWidth
139193
variant="contained"
140-
color="primary"
194+
color="default"
141195
className={classes.submit}
142196
onClick={e => handleLogin(e)}
143197
>
144198
Sign In
145199
</Button>
146200

147-
<a href="https://localhost:8080/github">
201+
<Button
202+
fullWidth
203+
variant="contained"
204+
color="default"
205+
className={classes.submit}
206+
href="https://localhost:8080/github"
207+
>
208+
<GitHubIcon/>
209+
</Button>
210+
211+
{/* <a href="https://localhost:8080/github">
148212
<img src="/images/githublogin.png" />
149213
</a>
150-
<br></br>
214+
<br></br> */}
151215
<Grid container>
152216
<Grid item xs>
153-
<Link href="#" variant="body2">
217+
{/* <Link href="#" variant="body2">
154218
Forgot password?
155-
</Link>
219+
</Link> */}
220+
<RouteLink to={`/signup`} className="nav_link">Forgot password?</RouteLink>
156221
</Grid>
157222
<Grid item>
158223
<RouteLink to={`/signup`} className="nav_link">

0 commit comments

Comments
 (0)