Skip to content

Commit b3f6ae2

Browse files
committed
login/signup/signout mostly done, cookie/localstorage in progress
1 parent e9a6fb3 commit b3f6ae2

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const {
1111
shell,
1212
dialog,
1313
ipcMain,
14-
globalShortcut
14+
globalShortcut,
15+
session
1516
} = require('electron');
1617

1718
// Uncomment below for hot reloading during development
@@ -264,9 +265,9 @@ const createWindow = () => {
264265

265266
// UNCOMMENT THIS DURING DEVELOPMENT TO ENABLE CONSOLE TO OPEN UPON LAUNCH
266267
// dev tools opened on every browser creation
267-
// mainWindow.webContents.once('dom-ready', () => {
268-
// mainWindow.webContents.openDevTools();
269-
// });
268+
mainWindow.webContents.once('dom-ready', () => {
269+
mainWindow.webContents.openDevTools();
270+
});
270271
};
271272

272273
// This method will be called when Electron has finished

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"@types/react": "^16.8.14",
118118
"@types/react-dom": "^16.8.4",
119119
"@types/react-redux": "^7.0.8",
120+
"@types/react-router-dom": "^5.1.5",
120121
"@types/react-syntax-highlighter": "^11.0.4",
121122
"ace-builds": "^1.4.8",
122123
"app-root-path": "^3.0.0",

server/controllers/cookieController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const cookieController = {};
33
// setSSIDCookie - store the user id from database in cookie
44
cookieController.setSSIDCookie = (req, res, next) => {
55
// set cookie with key 'ssid' and value to user's id, also set http only
6-
res.cookie('ssid', res.locals.id, { maxAge: 3600 });
6+
res.cookie('ssid', res.locals.id, { maxAge: 3600000 });
77
console.log('Successful setSSIDCookie');
88
return next();
99
};

server/controllers/userController.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ const userController = {};
66
const bcrypt = require('bcryptjs');
77

88
userController.createUser = (req, res, next) => {
9-
console.log('Inside createUser');
9+
console.log('Creating user...');
1010
const { username, password } = req.body;
1111
// error handling if username or password is missing
12-
if (!username || !password) {
13-
return next('Missing username or password in userController.createUser');
12+
if (!username) {
13+
return res.status(400).json('No username input');
14+
}
15+
if (!password) {
16+
return res.status(400).json('No password input');
1417
}
1518
const projects = [];
1619
// create user using username and password
@@ -24,7 +27,7 @@ userController.createUser = (req, res, next) => {
2427
});
2528
} else {
2629
// this id property will be used in other middleware for cookie
27-
console.log('Successfule createUser');
30+
console.log('Successful createUser');
2831
res.locals.id = newUser.id;
2932
return next();
3033
}
@@ -35,11 +38,13 @@ userController.createUser = (req, res, next) => {
3538
// the appropriate user in the database, and then authenticate the submitted password against the password stored in the database.
3639

3740
userController.verifyUser = (req, res, next) => {
38-
console.log('Inside verifyUser');
39-
console.log('req.body is', req.body);
41+
console.log('Verifying user...');
4042
const { username, password } = req.body;
41-
if (!username || !password) {
42-
return res.status(400).json('No username or password input');
43+
if (!username) {
44+
return res.status(400).json('No username input');
45+
}
46+
if (!password) {
47+
return res.status(400).json('No password input');
4348
}
4449
Users.findOne({ username }, (err, user) => {
4550
if (err) {

src/components/login/SignIn.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import React, { Component, useState } from 'react';
33
import { LoginInt } from '../../interfaces/Interfaces';
44
import { setUsername, setPassword } from '../../actions/actionCreators';
55
//import { useSelector } from 'react-redux';
6-
import {
7-
Link as RouteLink,
8-
withRouter,
9-
useHistory,
10-
Redirect
11-
} from 'react-router-dom';
6+
import { Link as RouteLink, withRouter, useHistory } from 'react-router-dom';
127

138
import Avatar from '@material-ui/core/Avatar';
149
import Button from '@material-ui/core/Button';
@@ -103,22 +98,24 @@ const SignIn: React.FC<LoginProps> = props => {
10398
username,
10499
password
105100
});
106-
console.log(body);
107101
fetch('http://localhost:8080/login', {
108102
method: 'POST',
109-
mode: 'cors',
103+
credentials: 'include',
110104
headers: {
111105
'Content-Type': 'application/json'
112106
},
113107
body
114108
})
115-
.then(res => res.json())
109+
.then(res => {
110+
return res.json();
111+
})
116112
.then(data => {
117113
if (typeof data === 'string') {
118114
alert(data);
119115
} else {
120-
alert('Login successful!');
121116
props.history.push('/app');
117+
alert('Login successful!');
118+
console.log('Data is', data);
122119
}
123120
})
124121
.catch(err => console.log(err));

src/components/login/SignUp.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,21 @@ const SignUp: React.FC<LoginProps> = props => {
9898
fetch('http://localhost:8080/signup', {
9999
method: 'POST',
100100
mode: 'cors',
101+
credentials: 'include',
101102
headers: {
102103
'Content-Type': 'application/json'
103104
},
104105
body
105106
})
106107
.then(res => res.json())
107-
.then(data => console.log('Data from signup is:', data))
108+
.then(data => {
109+
if (typeof data === 'string') {
110+
alert(data);
111+
} else {
112+
props.history.push('/');
113+
alert('Signup successful! Please sign in to continue.');
114+
}
115+
})
108116
.catch(err => console.log(err));
109117
};
110118

0 commit comments

Comments
 (0)