Skip to content

Commit ad9b7ce

Browse files
committed
fixed current userlist updating automatically but turned off verifyAdmin in server router - check logic for getUpdatedUserList in newUserHelper l 16 as the interaction with the store is not set up correctly
1 parent 19fb00a commit ad9b7ce

File tree

3 files changed

+72
-52
lines changed

3 files changed

+72
-52
lines changed

server/routes/adminRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const router = express.Router();
1111

1212
// Route Handler: Checks if client has sysadmin privilege. Get all users from users table and send back to client (system admin)
1313
router.post('/',
14-
userController.verifySysadmin,
14+
// userController.verifySysadmin,
1515
userController.getAllUsers,
1616
(req, res) => {
1717
if(res.locals.error) return res.status(200).json(res.locals.error);
Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
1+
// THIS ENTIRE CODE BLOCK DOES NOT SEEM TO DO ANYTHING - COMMENTING IT OUT DOES NOT
2+
// AFFECT THE ABILITY TO LOG IN - TM OCT 202o
3+
14
// callback function invoked when 'login' button is clicked
2-
export const handleLogin = (e) => {
3-
e.preventDefault(); // prevents form submit from reloading page
4-
const usernameInput = document.getElementById('username');
5-
const passwordInput = document.getElementById('password');
6-
const username = usernameInput.value;
7-
const password = passwordInput.value;
5+
// export const handleLogin = (e) => {
6+
// e.preventDefault(); // prevents form submit from reloading page
7+
// const usernameInput = document.getElementById('username');
8+
// const passwordInput = document.getElementById('password');
9+
// const username = usernameInput.value;
10+
// const password = passwordInput.value;
811

9-
// clears input fields after login
10-
usernameInput.value = '';
11-
passwordInput.value = '';
12+
// // clears input fields after login
13+
// usernameInput.value = '';
14+
// passwordInput.value = '';
1215

13-
authenticateUser(username, password);
14-
};
16+
// // authenticateUser(username, password);
17+
// };
1518

16-
export const authenticateUser = (username, password) => {
17-
fetch('http://localhost:3000/login',
18-
{
19-
method: 'POST',
20-
headers: {
21-
'Content-Type': 'application/json',
22-
},
23-
body: JSON.stringify({
24-
username: username,
25-
password: password
26-
}),
27-
})
28-
.then((response) => {
29-
return response.json();
30-
})
31-
.then((data) => {
32-
if (typeof data === 'object') {
33-
window.alert(data.error);
34-
} else {
35-
console.log('LOGGED IN');
36-
}
37-
})
38-
.catch((err) => {
39-
console.log('authenticateUser ERR: ', err);
40-
return (err);
41-
});
42-
};
19+
// export const authenticateUser = (username, password) => {
20+
// console.log('username & password: ', username, password);
21+
// fetch('http://localhost:3000/login',
22+
// {
23+
// method: 'POST',
24+
// headers: {
25+
// 'Content-Type': 'application/json',
26+
// },
27+
// body: JSON.stringify({
28+
// username: username,
29+
// password: password
30+
// }),
31+
// })
32+
// .then((response) => {
33+
// console.log('in login helper response')
34+
// return response.json();
35+
// // response = response.json();
36+
// // console.log('response from auth: ', response);
37+
// })
38+
// .then((data) => {
39+
// if (typeof data === 'object') {
40+
// window.alert(data.error);
41+
// } else {
42+
// console.log('LOGGED IN');
43+
// return(data);
44+
// }
45+
// })
46+
// .catch((err) => {
47+
// console.log('authenticateUser ERR: ', err);
48+
// return (err);
49+
// });
50+
// };

src/components/helper/newUserHelper.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*/
55
import store from '../../renderer/store';
66
import * as actions from '../../actions/actions';
7+
import { NetworkCellSharp, NextWeek } from '@material-ui/icons';
8+
import { username } from '../../../security/email';
9+
// TM - no react-redux imports?
710

811
export const handleNewUser = (e) => {
912
e.preventDefault();
@@ -26,12 +29,10 @@ export const handleNewUser = (e) => {
2629
}
2730
if (!checkPhone(phone)) {
2831
window.alert(
29-
'Warning: Please enter a valid phone number with country code (+1) in the following format:\n\n+12345678900'
30-
);
32+
'Warning: Please enter a valid phone number with country code (+1) in the following format:\n\n+12345678900');
3133
return;
3234
}
33-
console.log('sending user data to createNewUser');
34-
// return createNewUser(email, username, password, phone);
35+
3536
createNewUser(email, username, password, phone);
3637
};
3738

@@ -55,10 +56,11 @@ export const confirmPassword = () => {
5556
export const checkPasswordLength = () => {
5657
const passwordLengthAlert = document.getElementById('password-length-alert');
5758
const password = document.getElementById('signupPassword').value;
59+
const regex = /^(?=[a-z\d]{6,}$)(?=\d*[a-z])[a-z]*\d[a-z\d]*$/;
5860

59-
if (password.length < 6) {
61+
if (!regex.test(password)) {
6062
passwordLengthAlert.innerHTML =
61-
'Warning: Password must be 6 characters or longer';
63+
'\nWarning: Password must be 6 characters or longer \nand must include at least one number and one letter';
6264
} else {
6365
passwordLengthAlert.innerHTML = '';
6466
}
@@ -101,36 +103,46 @@ export const createNewUser = (email, username, password, phone) => {
101103

102104
window.alert(`New user has been successfully created. \n\n
103105
An email with the user's credentials and login instructions has been sent to ${email}`);
104-
106+
107+
}). then (() =>{
105108
getUpdatedUserList();
106109
})
107110
.catch((err) => {
108111
console.log(err);
109112
});
110113
};
111114

115+
112116
export const getUpdatedUserList = () => {
113-
console.log('store username: ', store.userInfo.username);
117+
118+
// TM: Added this - do we need to use mapStateToProps to access the signed-in user's info?
119+
// const mapStateToProps = state => {
120+
// console.log(state);
121+
// return{
122+
// username: state.session.userName,
123+
// token: state.session.token
124+
// }};
125+
126+
114127
fetch('http://localhost:3000/admin', {
115128
method: 'POST',
116129
headers: {
117130
'Content-Type': 'application/json',
118131
},
119132
body: JSON.stringify({
120-
username: store.userInfo.username,
121-
token: store.userInfo.token,
133+
// username: store.userInfo.username, //TM: Accessing store.userInfo.username returns undefined - this is original code
134+
// token: store.userInfo.token,
122135
}),
123136
})
124137
.then((response) => response.json())
125138
.then((data) => {
126-
console.log('this is data from newUserHelper', data);
127139
updateUserList(data);
128140
})
129141
.catch((err) => {
130142
console.log('error in getUpdatedUserList: ', err);
131-
})
143+
});
132144
};
133145

134-
export const updateUserList = (data) => {
146+
export const updateUserList = (data) => { // TM: react-redux is not imported but this is still working... redux is stupid
135147
store.dispatch(actions.updateUserList(data));
136148
};

0 commit comments

Comments
 (0)