Loginauth / templates /register.html
Gregniuki's picture
Update templates/register.html
b67759d verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<footer>
<p>Copyright © Your Website</p>
</footer>
<div class="background-container">
<div class="color-overlay"></div>
<h1>Register</h1>
<a href="{{ google_oauth_url }}">Register with Google</a>
<form action="/register" method="post" id="registration-form" onsubmit="handleSubmit(event)">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required><br><br>
<input type="hidden" id="recaptcha_token" name="recaptcha_token" value="">
<div class="g-recaptcha" data-sitekey="6LeSJgwpAAAAAD9UlPdC911k8UgD6Uh3068xXgGj" data-callback="setRecaptchaToken"></div>
<br>
<button type="submit" id="submit-button">Register</button>
</form>
</div>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function setRecaptchaToken(token) {
document.getElementById('recaptcha_token').value = token;
}
function areFieldsFilled() {
var username = document.getElementById('username').value.trim();
var email = document.getElementById('email').value.trim();
var password = document.getElementById('password').value.trim();
var confirmPassword = document.getElementById('confirm_password').value.trim();
var recaptchaToken = document.getElementById('recaptcha_token').value.trim();
return username && email && password && confirmPassword && recaptchaToken;
}
function handleSubmit(event) {
event.preventDefault();
if (!areFieldsFilled()) {
alert("Please fill in all required fields and complete the reCAPTCHA.");
return;
}
var formData = new FormData(event.target);
fetch('/register', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
storeAccessToken(data.access_token);
window.location.href = `${data.redirect_url}?token=${data.access_token}`;
})
.catch(error => {
console.error('Error:', error);
});
}
function storeAccessToken(token) {
// Implement your token storage logic here
console.log("Token stored:", token);
}
</script>
</body>
</html>