Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlay working #15

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 51 additions & 47 deletions Client/components/login.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import * as actions from '../actionCreator/actionCreator.js'
import * as actions from '../actionCreator/actionCreator.js';

const login = () => {
const dispatch = useDispatch();

const loginFunc = (event) => {
event.preventDefault()
const un = document.getElementById('usernameLogin').value;
const pw = document.getElementById('passwordLogin').value;

const loginObj = {
username : un,
password : pw
const dispatch = useDispatch();

const loginFunc = (event) => {
event.preventDefault();
const un = document.getElementById('usernameLogin').value;
const pw = document.getElementById('passwordLogin').value;

const loginObj = {
username: un,
password: pw,
};

console.log(loginObj);

fetch('http://localhost:3000/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(loginObj),
})
.then((data) => data.json())
.then((data) => {
if (!data.err) {
console.log(data);
// Do something
// change logged in user state with the returned userState
dispatch(actions.updateUSER_LOG_ON(data));

// disable opacity
document.getElementById('overlay').style.display = 'none';
} else {
alert(data.err);
}
})
.catch((error) => alert(error));
};

return (
<div>
<form>
<input type="text" id="usernameLogin" placeholder="Username"></input>
<input
type="password"
id="passwordLogin"
placeholder="Password"
></input>
<button onClick={(event) => loginFunc(event)}>Login</button>
</form>
</div>
);
};

console.log(loginObj)

fetch('http://localhost:3000/login', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(loginObj)
})
.then( data => data.json())
.then( data => {
if (!data.err) {
console.log(data)
// Do something
// change logged in user state with the returned userState
dispatch(actions.updateUSER_LOG_ON(data))

// disable opacity
document.getElementById("overlay").style.display = 'none'
} else {
alert(data.err)
}
})
.catch(error => alert(error))
}

return(
<div>
<form>
<input type='text' id='usernameLogin' placeholder='Username'></input>
<input type='password' id='passwordLogin' placeholder='Password'></input>
<button onClick={event => loginFunc(event)}>Login</button>
</form>
</div>
)
}

export default login;
export default login;
88 changes: 48 additions & 40 deletions Client/components/signup.jsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
import React from 'react';
import { useDispatch } from 'react-redux'
import * as actions from '../actionCreator/actionCreator.js'
import { useDispatch } from 'react-redux';
import * as actions from '../actionCreator/actionCreator.js';

const signup = () => {
const dispatch = useDispatch();
const dispatch = useDispatch();

const signupFunc = (event) => {
event.preventDefault();
const username = document.getElementById('usernameSignup').value;
const password1 = document.getElementById('passwordSignup').value;
const password2 = document.getElementById('passwordSignupConfirm').value;
const signupFunc = (event) => {
event.preventDefault();
const username = document.getElementById('usernameSignup').value;
const password1 = document.getElementById('passwordSignup').value;
const password2 = document.getElementById('passwordSignupConfirm').value;

// check if passwords match
if (password1 !== password2) {
return alert("Sign up passwords do not match");
}

fetch('http://localhost:3000/user', {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username, password: password1})
})
.then( data => data.json())
.then( data => {
// if there is an error object
if (data.err) alert(data.err);
// update logged in user
dispatch(actions.updateUSER_LOG_ON(data));
// disable opacity
document.getElementById("overlay").style.display = 'none'
})
.catch(error => alert(error));
// check if passwords match
if (password1 !== password2) {
return alert('Sign up passwords do not match');
}

return (
<div>
<form>
<input type='text' id='usernameSignup' placeholder='Username'></input>
<input type='password' id='passwordSignup' placeholder='Password'></input>
<input type='password' id='passwordSignupConfirm' placeholder='Confirm Password'></input>
<button onClick={event => signupFunc(event)}>Login</button>
</form>
</div>
)
}
fetch('http://localhost:3000/user', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password: password1 }),
})
.then((data) => data.json())
.then((data) => {
// if there is an error object
if (data.err) alert(data.err);
// update logged in user
dispatch(actions.updateUSER_LOG_ON(data));
// disable opacity
document.getElementById('overlay').style.display = 'none';
})
.catch((error) => alert(error));
};

return (
<div>
<form>
<input type="text" id="usernameSignup" placeholder="Username"></input>
<input
type="password"
id="passwordSignup"
placeholder="Password"
></input>
<input
type="password"
id="passwordSignupConfirm"
placeholder="Confirm Password"
></input>
<button onClick={(event) => signupFunc(event)}>Sign Up</button>
</form>
</div>
);
};

export default signup
export default signup;
13 changes: 13 additions & 0 deletions Client/stylesheets/_flexios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,16 @@ li:last-child {
margin-right: 5px;
margin-bottom: 10px;
}
#overlay {
position: fixed;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: black;
z-index: 2;
cursor: pointer;
}