Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react-flow": "^1.0.3",
"react-flow-renderer": "^10.3.17",
"react-router": "^6.22.1",
"react-router-dom": "^6.22.1",
"react-router-dom": "^6.23.0",

@weikunwu weikunwu May 5, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the router upgrade required?

"react-scripts": "5.0.1",
"reactflow": "^11.10.4",
"typescript": "^4.9.5",
Expand Down
69 changes: 68 additions & 1 deletion src/Components/LogIn.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import HumaaansWireframe from '../Images/Humaaans Wireframe.png';
import React, { useState } from 'react';
import '../Styles/login.modules.css';

interface Props {
backToHomeHandler: () => void;
}

function LogIn({backToHomeHandler}: Props) {
const url = 'http://localhost:4000/login';


const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [successMessage, setSuccessMessage] = useState('');

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email, password })
});

if (response.ok) {
setSuccessMessage('Login successful');
setEmail('');
setPassword('');
window.location.href = '/profile';
} else if (response.status === 404) {
setErrorMessage('User not found');
} else if (response.status === 401) {
setErrorMessage('Invalid credentials');
} else {
setErrorMessage('Error connecting to server');
}
} catch (error) {
console.error('Error:', error);
setErrorMessage('Error connecting to server');
}
};

return (
<div style={{
margin: 0,
Expand Down Expand Up @@ -37,7 +76,7 @@ function LogIn({backToHomeHandler}: Props) {
If you are already a member you can login with your email address and password.
</div>

<div id="username-and-password">
{/* <div id="username-and-password">
Comment thread
zhangsscc99 marked this conversation as resolved.
Outdated
<form>
<label htmlFor="username"> User name</label><br />
<input type="text" id="user-name" name="username" /><br />
Expand All @@ -49,6 +88,34 @@ function LogIn({backToHomeHandler}: Props) {
Remember me <br />
<button type="submit" id="login"> Log In </button>
</form>
</div> */}

<div id="username-and-password">
<form onSubmit={handleSubmit}>
<label htmlFor="username"> Email address</label><br />
<input
type="email"
id="user-email"
name="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/><br />

<label htmlFor="password"> Password</label><br />
<input
type="password"
id="password"
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/><br />

<button type="submit" id="login"> Log In </button>
</form>
{errorMessage && <div>{errorMessage}</div>}
{successMessage && <div>{successMessage}</div>}
</div>
<div>
Don't have an account? <a href="/SignUp">Sign up here</a>
Expand Down
54 changes: 53 additions & 1 deletion src/Components/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import HumaaansWireframe from '../Images/Humaaans Wireframe.png';
import '../Styles/SignUp.modules.css';
import React, { useState } from 'react';

interface Props {
backToLoginHandler: () => void;
}

function SignUp({backToLoginHandler}: Props) {

const url = 'http://localhost:4000/register';
Comment thread
zhangsscc99 marked this conversation as resolved.


const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [message, setMessage] = useState('');

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

try {
const response = await fetch('http://localhost:4000/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, password }),
});

if (response.ok) {
// 注册成功
setMessage('Registration successful!');
window.location.href = '/login';
} else {
// 注册失败
const errorMessage = await response.text();
setMessage(`Registration failed: ${errorMessage}`);
}
} catch (error) {
// 请求发送失败
setMessage('Failed to connect to the server.');
}
};

return (
<div style={{
margin: 0,
Expand All @@ -30,7 +66,7 @@ function SignUp({backToLoginHandler}: Props) {
Become a member and enjoy pro learning
</div>

<div id="sign-up-form">
{/* <div id="sign-up-form">
<form>
<div id="sign-up-fields">
<div id="float-left">
Expand All @@ -41,6 +77,7 @@ function SignUp({backToLoginHandler}: Props) {
<label htmlFor="last-name" >Last name</label><br />
<input type="text" className="name" name="last-name"/>
</div>

</div>
<label htmlFor="emailaddress"> Email address</label><br />
<input type="text" id="emailaddress" name="email-address"/><br />
Expand All @@ -50,7 +87,22 @@ function SignUp({backToLoginHandler}: Props) {
<button type="submit" id="submitt"> Submit </button>

</form>
</div> */}




<div id="sign-up-form">
<form onSubmit={handleSubmit}>
<label htmlFor="emailaddress"> Email address</label><br />
<input type="text" id="emailaddress" name="email-address" value={email} onChange={(e) => setEmail(e.target.value)} /><br />
<label htmlFor="pass-word"> password</label><br />
<input type="password" id="pass-word" name="pass-word" value={password} onChange={(e) => setPassword(e.target.value)} /><br />

<button type="submit" id="submitt"> Submit </button>
</form>
</div>
{message && <div>{message}</div>}
</div>
</div>
</div>
Expand Down