a
This commit is contained in:
parent
63f07add82
commit
8133bc7aca
@ -1,36 +0,0 @@
|
||||
function validateFormLogin() {
|
||||
var email = document.getElementById('email').value;
|
||||
var password = document.getElementById('password').value;
|
||||
|
||||
// Perform basic validation
|
||||
if (!email || !password) {
|
||||
alert('Please enter both email and password');
|
||||
return;
|
||||
}
|
||||
|
||||
sendDataToServer(email, password);
|
||||
}
|
||||
|
||||
function sendDataToServer(email, password) {
|
||||
// Use AJAX or fetch to send data to the server
|
||||
// Example using fetch:
|
||||
fetch('/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ email, password }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Handle the response from the server
|
||||
console.log(data);
|
||||
if (data.success) {
|
||||
// Redirect or perform other actions for successful login
|
||||
alert('Login successful');
|
||||
} else {
|
||||
alert('Login failed. Please check your credentials.');
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
const express = require('express');
|
||||
const dotenv = require('dotenv');
|
||||
const bodyParser = require('body-parser');
|
||||
const mysql = require('mysql');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
||||
app.use(express.static('public'));
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
const db = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: 'your_mysql_password',
|
||||
database: 'your_database_name',
|
||||
});
|
||||
|
||||
db.connect(err => {
|
||||
if (err) {
|
||||
console.error('Error connecting to MySQL:', err);
|
||||
} else {
|
||||
console.log('Connected to MySQL');
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/signup', (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
|
||||
// Perform server-side validation if needed
|
||||
|
||||
const sql = 'INSERT INTO users (username, password) VALUES (?, ?)';
|
||||
db.query(sql, [username, password], (err, result) => {
|
||||
if (err) {
|
||||
console.error('Error executing SQL query:', err);
|
||||
res.status(500).json({ success: false, message: 'Internal Server Error' });
|
||||
} else {
|
||||
console.log('User signed up successfully');
|
||||
res.json({ success: true, message: 'User signed up successfully' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on http://localhost:${port}`);
|
||||
});
|
@ -1,53 +0,0 @@
|
||||
function validateFormSignup() {
|
||||
var username = document.getElementById('username').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var password = document.getElementById('password').value;
|
||||
var confirmPassword = document.getElementById('confirmPassword').value;
|
||||
|
||||
|
||||
if (!/^[a-zA-Z0-9]+$/.test(username)) {
|
||||
alert("Username can only contain letters and numbers.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)) {
|
||||
alert("Enter a valid email address.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/.test(password)) {
|
||||
alert("Password must be more than 8 characters and contain at least 1 upper and lower case letter and 1 special character.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
alert('Passwords do not match');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!signupCheck.checked) {
|
||||
alert("Please accept the terms & conditions to proceed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If validation passes, send data to the server
|
||||
sendDataToServer(username, email, password);
|
||||
}
|
||||
|
||||
function sendDataToServer(username, password) {
|
||||
// Use AJAX or fetch to send data to the server
|
||||
// Example using fetch:
|
||||
fetch('/signup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ username, email, password }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Handle the response from the server
|
||||
console.log(data);
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
|
||||
<title>Hello, world!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user