Skip to content

Commit f4bba0d

Browse files
committed
Merge branch 'master' into projectManagement
2 parents 2d7cf7c + ac1bfd1 commit f4bba0d

File tree

6 files changed

+267
-66
lines changed

6 files changed

+267
-66
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/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
};

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)