Spaces:
Running
Running
File size: 6,335 Bytes
7eeea54 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IntelliFarm Pro | Login</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
.auth-bg {
background: linear-gradient(135deg, rgba(34,197,94,0.1) 0%, rgba(16,163,74,0.2) 100%);
}
</style>
</head>
<body class="auth-bg min-h-screen flex items-center justify-center">
<div class="max-w-md w-full bg-white rounded-lg shadow-xl overflow-hidden">
<div class="p-8">
<div class="text-center mb-8">
<div class="flex justify-center">
<i data-feather="sun" class="text-primary-600 h-10 w-10"></i>
</div>
<h1 class="mt-4 text-2xl font-bold text-gray-900">Welcome to IntelliFarm Pro</h1>
<p class="mt-2 text-gray-600">Sign in to your account</p>
</div>
<form id="loginForm" class="space-y-6">
<div>
<label for="email" class="block text-sm font-medium text-gray-700">Email address</label>
<div class="mt-1 relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i data-feather="mail" class="h-4 w-4 text-gray-400"></i>
</div>
<input id="email" name="email" type="email" autocomplete="email" required
class="py-2 pl-10 block w-full border border-gray-300 rounded-md focus:ring-primary-500 focus:border-primary-500"
placeholder="you@example.com">
</div>
</div>
<div>
<label for="password" class="block text-sm font-medium text-gray-700">Password</label>
<div class="mt-1 relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i data-feather="lock" class="h-4 w-4 text-gray-400"></i>
</div>
<input id="password" name="password" type="password" autocomplete="current-password" required
class="py-2 pl-10 block w-full border border-gray-300 rounded-md focus:ring-primary-500 focus:border-primary-500"
placeholder="••••••••">
</div>
</div>
<div class="flex items-center justify-between">
<div class="flex items-center">
<input id="remember-me" name="remember-me" type="checkbox"
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded">
<label for="remember-me" class="ml-2 block text-sm text-gray-700">Remember me</label>
</div>
<div class="text-sm">
<a href="/forgot-password" class="font-medium text-primary-600 hover:text-primary-500">
Forgot password?
</a>
</div>
</div>
<div>
<button type="submit"
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500">
Sign in
</button>
</div>
</form>
<div class="mt-6">
<p class="text-center text-sm text-gray-600">
Don't have an account?
<a href="/register" class="font-medium text-primary-600 hover:text-primary-500">
Register here
</a>
</p>
</div>
</div>
</div>
<script>
feather.replace();
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = {
email: document.getElementById('email').value,
password: document.getElementById('password').value,
remember: document.getElementById('remember-me').checked
};
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData)
});
const data = await response.json();
if (response.ok) {
// Store token and redirect based on user role
localStorage.setItem('token', data.token);
localStorage.setItem('userRole', data.user.role);
switch(data.user.role) {
case 'admin':
window.location.href = '/admin/dashboard';
break;
case 'manager':
window.location.href = '/manager/dashboard';
break;
case 'technician':
window.location.href = '/technician/dashboard';
break;
case 'worker':
window.location.href = '/worker/dashboard';
break;
default:
window.location.href = '/';
}
} else {
alert(data.message || 'Login failed');
}
} catch (error) {
console.error('Login error:', error);
alert('An error occurred during login');
}
});
</script>
</body>
</html> |