335 lines
9.7 KiB
HTML
335 lines
9.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - Water Station Tracker</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 1rem;
|
|
}
|
|
|
|
.login-container {
|
|
background: white;
|
|
padding: 2rem;
|
|
border-radius: 12px;
|
|
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.login-header h1 {
|
|
color: #333;
|
|
font-size: 1.8rem;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.login-header p {
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: #333;
|
|
font-weight: 500;
|
|
}
|
|
|
|
input[type="text"],
|
|
input[type="email"],
|
|
input[type="password"] {
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border: 2px solid #e1e1e1;
|
|
border-radius: 6px;
|
|
font-size: 1rem;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
input[type="text"]:focus,
|
|
input[type="email"]:focus,
|
|
input[type="password"]:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s;
|
|
margin-bottom: 1rem;
|
|
display: inline-block;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: #667eea;
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: #5a6fd8;
|
|
}
|
|
|
|
.btn-google {
|
|
background: #db4437;
|
|
color: white;
|
|
width: 49%;
|
|
}
|
|
|
|
.btn-google:hover {
|
|
background: #c23321;
|
|
}
|
|
|
|
.btn-instagram {
|
|
background: #e4405f;
|
|
color: white;
|
|
width: 49%;
|
|
}
|
|
|
|
.btn-instagram:hover {
|
|
background: #d62d46;
|
|
}
|
|
|
|
.divider {
|
|
text-align: center;
|
|
margin: 1.5rem 0;
|
|
color: #666;
|
|
position: relative;
|
|
}
|
|
|
|
.divider::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 0;
|
|
right: 0;
|
|
height: 1px;
|
|
background: #e1e1e1;
|
|
}
|
|
|
|
.divider span {
|
|
background: white;
|
|
padding: 0 1rem;
|
|
}
|
|
|
|
.toggle-form {
|
|
text-align: center;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.toggle-form a {
|
|
color: #667eea;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.toggle-form a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.back-link {
|
|
text-align: center;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.back-link a {
|
|
color: #667eea;
|
|
text-decoration: none;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.error {
|
|
color: #f44336;
|
|
font-size: 0.9rem;
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.success {
|
|
color: #4CAF50;
|
|
font-size: 0.9rem;
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
@media (max-width: 480px) {
|
|
.login-container {
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.login-header h1 {
|
|
font-size: 1.5rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-header">
|
|
<h1>💧 Water Station Tracker</h1>
|
|
<p>Login to manage water stations</p>
|
|
</div>
|
|
|
|
<div id="login-form">
|
|
<form id="loginForm">
|
|
<div class="form-group">
|
|
<label for="username">Username</label>
|
|
<input type="text" id="username" name="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Login</button>
|
|
</form>
|
|
|
|
<div class="divider">
|
|
<span>or</span>
|
|
</div>
|
|
|
|
<a href="/auth/google" class="btn btn-google">Google</a>
|
|
<a href="/auth/instagram" class="btn btn-instagram">Instagram</a>
|
|
|
|
<div class="toggle-form">
|
|
<a href="#" onclick="toggleForm()">Don't have an account? Register</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="register-form" style="display: none;">
|
|
<form id="registerForm">
|
|
<div class="form-group">
|
|
<label for="reg-username">Username</label>
|
|
<input type="text" id="reg-username" name="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="reg-email">Email</label>
|
|
<input type="email" id="reg-email" name="email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="reg-password">Password</label>
|
|
<input type="password" id="reg-password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Register</button>
|
|
</form>
|
|
|
|
<div class="divider">
|
|
<span>or</span>
|
|
</div>
|
|
|
|
<a href="/auth/google" class="btn btn-google">Sign up with Google</a>
|
|
<a href="/auth/instagram" class="btn btn-instagram">Sign up with Instagram</a>
|
|
|
|
<div class="toggle-form">
|
|
<a href="#" onclick="toggleForm()">Already have an account? Login</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="message"></div>
|
|
|
|
<div class="back-link">
|
|
<a href="/">← Back to Map</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function toggleForm() {
|
|
const loginForm = document.getElementById('login-form');
|
|
const registerForm = document.getElementById('register-form');
|
|
|
|
if (loginForm.style.display === 'none') {
|
|
loginForm.style.display = 'block';
|
|
registerForm.style.display = 'none';
|
|
} else {
|
|
loginForm.style.display = 'none';
|
|
registerForm.style.display = 'block';
|
|
}
|
|
|
|
document.getElementById('message').innerHTML = '';
|
|
}
|
|
|
|
function showMessage(message, type = 'error') {
|
|
const messageDiv = document.getElementById('message');
|
|
messageDiv.innerHTML = `<div class="${type}">${message}</div>`;
|
|
}
|
|
|
|
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(e.target);
|
|
const data = Object.fromEntries(formData);
|
|
|
|
try {
|
|
const response = await fetch('/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
if (response.ok) {
|
|
window.location.href = '/dashboard';
|
|
} else {
|
|
showMessage('Invalid username or password');
|
|
}
|
|
} catch (error) {
|
|
showMessage('Login failed. Please try again.');
|
|
}
|
|
});
|
|
|
|
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(e.target);
|
|
const data = Object.fromEntries(formData);
|
|
|
|
try {
|
|
const response = await fetch('/auth/register', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
showMessage('Registration successful! Redirecting...', 'success');
|
|
setTimeout(() => {
|
|
window.location.href = '/dashboard';
|
|
}, 1500);
|
|
} else {
|
|
showMessage(result.error || 'Registration failed');
|
|
}
|
|
} catch (error) {
|
|
showMessage('Registration failed. Please try again.');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |