changed frontend

This commit is contained in:
2025-06-20 23:52:07 +02:00
parent 63d120cc4e
commit c26a19ec7b
4 changed files with 68 additions and 27 deletions

5
.gitignore vendored
View File

@@ -1,2 +1,5 @@
backend/.env backend/.env
# Ignore environment files # Ignore environment files
index.html
# Ignore frontend dev file

View File

@@ -25,3 +25,19 @@ export async function loginUser(username, password) {
return { success: false, message: "Invalid username or password" }; return { success: false, message: "Invalid username or password" };
} }
} }
export async function createUser(username, first_name, last_name, password, email) {
try {
const [result] = await pool.query(
"INSERT INTO users (username, first_name, last_name, password, email) VALUES (?, ?, ?, ?, ?)",
[username, first_name, last_name, password, email]
);
console.log("User created successfully: ", result);
return { success: true, userId: result.insertId };
} catch (error) {
console.error("Error creating user: ", error);
return { success: false, message: "Error creating user" };
}
}

View File

@@ -2,6 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<script> <script>
import { createUser } from "../database.js";
window.history.pushState({}, "", "<%= newLink %>"); window.history.pushState({}, "", "<%= newLink %>");
</script> </script>
<meta charset="utf-8" /> <meta charset="utf-8" />
@@ -15,7 +17,18 @@
/> />
</head> </head>
<body> <body>
<h1>Hello, <%= sqlResult.user.first_name %>.</h1> <div class="row">
<div class="column">
<h1>Hello, <%= sqlResult.user.first_name %>.</h1>
</div>
<div class="column">
<h1>Welcome to your dashboard.</h1>
</div>
<div class="column">
<button class="btn btn-danger">Logout</button>
</div>
</div>
<script <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js" src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"

View File

@@ -21,32 +21,41 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<div class="row"></div> <div class="row">
</div> <h1>Login page</h1>
</div>
<div class="row">
<form action="/login" method="post">
<div class="input-group">
<input
type="text"
name="username"
placeholder="Username"
class="form-control"
required
/>
<input
type="password"
name="password"
placeholder="Password"
class="form-control"
required
/>
<input
type="submit"
value="Login"
class="btn btn-primary"
onsubmit="this.form.submit()"
/>
</div>
</form>
</div>
<form action="/login" method="post"> <div class="alert alert-danger alter-dismissable fade show" role="alert">
<input <%= error %>
type="text" <button class="btn-close" aria-label="close" data-bs-dismiss="alert"></button>
name="username" </div>
placeholder="Username" </div>
class="form-control mb-2"
required
/>
<input
type="password"
name="password"
placeholder="Password"
class="form-control mb-2"
required
/>
<input
type="button"
value="Login"
class="btn btn-primary"
onclick="this.form.submit()"
/>
</form>
<p><%= error %></p>
<script <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js" src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q" integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q"