158 lines
5.7 KiB
Plaintext
158 lines
5.7 KiB
Plaintext
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Discord Clone - Sign Up</title>
|
|
<link rel="stylesheet" href="static/css/index.css"/>
|
|
</head>
|
|
<body>
|
|
<div class="signup-container">
|
|
<div class="signup-header">
|
|
<img src="/static/favicon.ico" class="logo"/>
|
|
<h1>Login</h1>
|
|
<p>Enter the chat</p>
|
|
</div>
|
|
|
|
<div class="signup-form">
|
|
<div class="success-message" id="successMessage">
|
|
Login successful, Redirecting
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input
|
|
type="text"
|
|
id="username"
|
|
name="username"
|
|
placeholder="Enter your username"
|
|
required
|
|
/>
|
|
<div class="error-message">Username is required</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<div class="input-wrapper">
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
placeholder="Enter your password"
|
|
required
|
|
/>
|
|
<button
|
|
type="button"
|
|
class="password-toggle"
|
|
id="passwordToggle"
|
|
>
|
|
SHOW
|
|
</button>
|
|
</div>
|
|
<div class="error-message">
|
|
Password must be at least 8 characters
|
|
</div>
|
|
</div>
|
|
|
|
<button type="button" class="submit-button" id="submitButton">
|
|
Login
|
|
</button>
|
|
</div>
|
|
|
|
<div class="signup-footer">
|
|
Dont have an account? <a href="/signup">Sign up</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const form = {
|
|
username: document.getElementById("username"),
|
|
password: document.getElementById("password"),
|
|
};
|
|
|
|
const submitButton = document.getElementById("submitButton");
|
|
const successMessage = document.getElementById("successMessage");
|
|
|
|
// Password toggle functionality
|
|
const passwordToggle = document.getElementById("passwordToggle");
|
|
|
|
passwordToggle.addEventListener("click", function () {
|
|
const type =
|
|
form.password.type === "password" ? "text" : "password";
|
|
form.password.type = type;
|
|
this.textContent = type === "password" ? "SHOW" : "HIDE";
|
|
});
|
|
|
|
function toggleError(input, hasError) {
|
|
const formGroup = input.closest(".form-group");
|
|
if (hasError) {
|
|
formGroup.classList.add("error");
|
|
} else {
|
|
formGroup.classList.remove("error");
|
|
}
|
|
}
|
|
|
|
// Form submission
|
|
submitButton.addEventListener("click", async function () {
|
|
|
|
// Disable button and show loading
|
|
submitButton.disabled = true;
|
|
submitButton.innerHTML =
|
|
'<span class="loading-spinner"></span>Logging In...';
|
|
|
|
// Prepare data
|
|
const formData = {
|
|
username: form.username.value.trim(),
|
|
password: form.password.value,
|
|
};
|
|
|
|
try {
|
|
// Replace with your actual backend endpoint
|
|
const response = await fetch(
|
|
"/api/login",
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(formData),
|
|
},
|
|
);
|
|
|
|
if (response.ok) {
|
|
// Show success message
|
|
successMessage.classList.add("show");
|
|
submitButton.innerHTML = "Logged in!!";
|
|
|
|
// setTimeout(() => {
|
|
// window.location.replace('/chat');
|
|
// }, 1000);
|
|
} else {
|
|
const error = await response.text();
|
|
throw new Error(error || "Login failed");
|
|
}
|
|
} catch (error) {
|
|
console.error("Login error:", error);
|
|
alert(
|
|
error.message ||
|
|
"Failed to login. Please try again.",
|
|
);
|
|
submitButton.disabled = false;
|
|
submitButton.innerHTML = "Login";
|
|
}
|
|
});
|
|
|
|
// Allow Enter key to submit
|
|
Object.values(form).forEach((input) => {
|
|
if (input.tagName === "INPUT") {
|
|
input.addEventListener("keypress", function (e) {
|
|
if (e.key === "Enter") {
|
|
submitButton.click();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|