Skip to content

Commit df06f78

Browse files
committed
fix merge conflicts after aaron signin/login update
2 parents 9999a72 + 2a30711 commit df06f78

File tree

15 files changed

+228
-268
lines changed

15 files changed

+228
-268
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"@material-ui/styles": "^4.9.6",
113113
"@types/enzyme": "^3.10.5",
114114
"@types/enzyme-adapter-react-16": "^1.0.6",
115+
"@types/js-cookie": "^2.2.6",
115116
"@types/prettier": "^1.19.0",
116117
"@types/prismjs": "^1.16.0",
117118
"@types/react": "^16.8.14",
@@ -137,6 +138,7 @@
137138
"electron-splashscreen": "^1.0.0",
138139
"enzyme": "^3.4.1",
139140
"enzyme-adapter-react-16": "^1.2.0",
141+
"js-cookie": "^2.2.1",
140142
"konva": "^4.2.0",
141143
"localforage": "^1.7.2",
142144
"lodash.throttle": "^4.1.1",

server/controllers/userController.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ const bcrypt = require('bcryptjs');
77

88
userController.createUser = (req, res, next) => {
99
console.log('Creating user...');
10-
const { username, password } = req.body;
10+
const { email, username, password } = req.body;
1111
// error handling if username or password is missing
1212
if (!username) {
1313
return res.status(400).json('No username input');
1414
}
15+
if (!email) {
16+
return res.status(400).json('No email input');
17+
}
1518
if (!password) {
1619
return res.status(400).json('No password input');
1720
}
18-
const projects = [];
21+
1922
// create user using username and password
20-
Users.create({ username, password, projects }, (err, newUser) => {
23+
Users.create({ email, username, password, projects: [] }, (err, newUser) => {
2124
if (err) {
2225
return next({
2326
log: `Error in userController.createUser: ${err}`,

server/models/userModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const Schema = mongoose.Schema;
55

66
const userSchema = new Schema({
77
username: { type: String, required: true, unique: true },
8+
email: { type: String, required: true, unique: true },
89
password: { type: String, required: true },
910
projects: Array
1011
});
1112

1213
// salt will go through 10 rounds of hashing
1314
const SALT_WORK_FACTOR = 10;
1415
const bcrypt = require('bcryptjs');
15-
const { session } = require('electron');
1616

1717
// mongoose middleware that will run before the save to collection happens (user gets put into database)
1818
// cannot use arrow function here as context of 'this' is important

src/actionTypes/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@ export const UPDATE_CHILDREN_SORT: string = 'UPDATE_CHILDREN_SORT';
4141
export const UPDATE_CODE: string = 'UPDATE_CODE';
4242
export const UPDATE_HTML_ATTR: string = 'UPDATE_HTML_ATTR';
4343

44-
export const SET_USERNAME: string = 'SET_USERNAME';
45-
export const SET_PASSWORD: string = 'SET_PASSWORD';
46-
export const LOGIN: string = 'LOGIN';
47-
export const SIGNUP: string = 'SIGNUP';
44+
export const SET_LOGIN_STATE: string = 'SET_LOGIN_STATE';

src/actions/actionCreators.ts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import {
3939
UNDO,
4040
UPDATE_HTML_ATTR,
4141
UPDATE_CODE,
42-
SET_USERNAME,
43-
SET_PASSWORD,
44-
LOGIN,
45-
SIGNUP
42+
SET_LOGIN_STATE
4643
} from '../actionTypes/index';
4744
import { loadState } from '../localStorage';
4845
import createFiles from '../utils/createFiles.util';
@@ -333,28 +330,6 @@ export const updateHtmlAttr = ({
333330
payload: { attr, value }
334331
});
335332

336-
export const setUsername = (username: string): Action => ({
337-
type: SET_USERNAME,
338-
payload: username
339-
});
340-
341-
export const setPassword = (password: string): Action => ({
342-
type: SET_PASSWORD,
343-
payload: password
344-
})
345-
346-
// export const login = (username: string, password: string) => ({
347-
// return (dispatch: any) => {
348-
// fetch('/login', {
349-
// method: 'POST',
350-
// body: JSON.stringify({ username, password })
351-
// })
352-
// .then(response => response.json())
353-
// .then(data => console.log(data))
354-
// }
355-
// })
356-
357-
// export const signup = (username: string, password: string): Action => ({
358-
// type: SIGNUP,
359-
// payload: { username, password }
360-
// })
333+
export const setLoginState = (): Action => ({
334+
type: SET_LOGIN_STATE
335+
})

src/components/login/SignIn.tsx

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import React, { Component, useState } from 'react';
2-
//import { connect } from 'react';
1+
import React, { Component, useState, useEffect } from 'react';
32
import { LoginInt } from '../../interfaces/Interfaces';
4-
import { setUsername, setPassword } from '../../actions/actionCreators';
5-
//import { useSelector } from 'react-redux';
6-
import { Link as RouteLink, withRouter, useHistory } from 'react-router-dom';
3+
import { setLoginState } from '../../actions/actionCreators';
4+
import { useSelector, useDispatch } from 'react-redux';
5+
import {
6+
Link as RouteLink,
7+
withRouter,
8+
useHistory,
9+
RouteComponentProps
10+
} from 'react-router-dom';
11+
import { sessionIsCreated } from '../../helperFunctions/auth';
712

813
import Avatar from '@material-ui/core/Avatar';
914
import Button from '@material-ui/core/Button';
@@ -18,24 +23,6 @@ import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
1823
import Typography from '@material-ui/core/Typography';
1924
import { makeStyles, withStyles } from '@material-ui/core/styles';
2025
import Container from '@material-ui/core/Container';
21-
import { render } from 'enzyme';
22-
23-
const mapStateToProps = (store: any) => ({
24-
username: store.credentials.username,
25-
password: store.credentials.password
26-
});
27-
28-
const mapDispatchToProps = (dispatch: any) => ({
29-
setUsername: (username: string) => dispatch(setUsername(username)),
30-
setPassword: (password: string) => dispatch(setPassword(password))
31-
// login: (username: string, password: string) => dispatch(login(username, password)),
32-
// signup: (username: string, password: string) => dispatch(signup(username, password)),
33-
});
34-
35-
interface LoginProps extends LoginInt {
36-
setUsername(username: string): void;
37-
setPassword(username: string): void;
38-
}
3926

4027
function Copyright() {
4128
return (
@@ -70,16 +57,15 @@ const useStyles = makeStyles(theme => ({
7057
}
7158
}));
7259

73-
const SignIn: React.FC<LoginProps> = props => {
60+
const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
7461
const classes = useStyles();
75-
//const count = useSelector(state => state);
62+
63+
const dispatch = useDispatch();
7664

7765
const [username, setUsername] = useState('');
7866
const [password, setPassword] = useState('');
7967

80-
const history = useHistory();
81-
82-
const handleChange = e => {
68+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
8369
let inputVal = e.target.value;
8470
switch (e.target.name) {
8571
case 'username':
@@ -91,34 +77,18 @@ const SignIn: React.FC<LoginProps> = props => {
9177
}
9278
};
9379

94-
const handleLogin = e => {
95-
console.log('click fired on handleLogin');
80+
const handleLogin = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
9681
e.preventDefault();
97-
const body = JSON.stringify({
98-
username,
99-
password
82+
console.log('click fired on handleLogin');
83+
sessionIsCreated(username, password).then(isLoggedIn => {
84+
if (isLoggedIn) {
85+
console.log('session created');
86+
dispatch(setLoginState()); // changes login state to true
87+
props.history.push('/');
88+
} else {
89+
console.log('invalid login');
90+
}
10091
});
101-
fetch('https://localhost:8080/login', {
102-
method: 'POST',
103-
credentials: 'include',
104-
headers: {
105-
'Content-Type': 'application/json'
106-
},
107-
body
108-
})
109-
.then(res => {
110-
return res.json();
111-
})
112-
.then(data => {
113-
if (typeof data === 'string') {
114-
alert(data);
115-
} else {
116-
props.history.push('/app');
117-
alert('Login successful!');
118-
//console.log('Data is', data);
119-
}
120-
})
121-
.catch(err => console.log(err));
12292
};
12393

12494
return (
@@ -167,7 +137,7 @@ const SignIn: React.FC<LoginProps> = props => {
167137
variant="contained"
168138
color="primary"
169139
className={classes.submit}
170-
onClick={handleLogin}
140+
onClick={e => handleLogin(e)}
171141
>
172142
Sign In
173143
</Button>
@@ -179,7 +149,9 @@ const SignIn: React.FC<LoginProps> = props => {
179149
</Link>
180150
</Grid>
181151
<Grid item>
182-
<RouteLink to={`/signup`}>Don't have an account? Sign Up</RouteLink>
152+
<RouteLink to={`/signup`} className="nav_link">
153+
Don't have an account? Sign Up
154+
</RouteLink>
183155
</Grid>
184156
</Grid>
185157
</div>

0 commit comments

Comments
 (0)