parent
7238e1ea8c
commit
71f513bdca
@ -0,0 +1,18 @@
|
|||||||
|
const mysql = require("mysql");
|
||||||
|
|
||||||
|
const connection = mysql.createConnection({
|
||||||
|
host: process.env.DB_HOST || 'localhost',
|
||||||
|
user: process.env.DB_USER || 'vinz',
|
||||||
|
password: process.env.DB_PASSWORD || '19735',
|
||||||
|
database: process.env.DB_NAME || 'maettleship'
|
||||||
|
});
|
||||||
|
|
||||||
|
connection.connect((err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Error connecting to the database:', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Connected to the MySQL database');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = connection;
|
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Connection View</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Register</h1>
|
||||||
|
<form id="registerForm">
|
||||||
|
<label for="email">Pseudo :</label>
|
||||||
|
<input type="text" id="pseudo" name="pseudo" required>
|
||||||
|
|
||||||
|
<label for="password">Password:</label>
|
||||||
|
<input type="password" id="password" name="password" required>
|
||||||
|
|
||||||
|
<button type="submit">Register</button>
|
||||||
|
</form>
|
||||||
|
<div id="message"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="../scripts/connection.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,31 @@
|
|||||||
|
document.getElementById('registerForm').addEventListener('submit', async function (event) {
|
||||||
|
event.preventDefault(); // Prevent the default form submission
|
||||||
|
|
||||||
|
const pseudo = document.getElementById('pseudo').value;
|
||||||
|
const password = document.getElementById('password').value;
|
||||||
|
const messageDiv = document.getElementById('message');
|
||||||
|
|
||||||
|
console.log("test")
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/register', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ pseudo, password }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
messageDiv.textContent = 'User registered successfully!';
|
||||||
|
messageDiv.style.color = 'green';
|
||||||
|
} else {
|
||||||
|
const errorText = await response.text();
|
||||||
|
messageDiv.textContent = `Error: ${errorText}`;
|
||||||
|
messageDiv.style.color = 'red';
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
messageDiv.textContent = `Error: ${error.message}`;
|
||||||
|
messageDiv.style.color = 'red';
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in new issue