-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
104 lines (91 loc) · 4.01 KB
/
index.html
File metadata and controls
104 lines (91 loc) · 4.01 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library Management System - Login</title>
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="alternate icon" href="favicon.svg">
<lin1k rel="mask-icon" href="favicon.svg" color="#2563eb">
<link rel="stylesheet" href="css/style.css">
</head>
<body class="login-page">
<div class="login-container">
<div class="login-box">
<div class="login-header">
<div class="logo">
<svg width="60" height="60" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"></path>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"></path>
</svg>
</div>
<h1>Library Management System</h1>
<p>Brainware University</p>
</div>
<form id="loginForm" class="login-form">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required autofocus>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div id="errorMessage" class="error-message" style="display: none;"></div>
<button type="submit" class="btn btn-primary btn-block">
<span id="loginText">Login</span>
<span id="loginLoader" class="loader" style="display: none;"></span>
</button>
</form>
<div class="login-footer">
<p><strong>Demo Credentials:</strong></p>
<p>Admin: <code>rahul.pal</code> / <code>rahul123</code></p>
<p>Librarian: <code>ajay.das</code> / <code>ajay123</code></p>
</div>
</div>
</div>
<script src="js/config.js"></script>
<script src="js/auth.js"></script>
<script>
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const errorDiv = document.getElementById('errorMessage');
const loginText = document.getElementById('loginText');
const loginLoader = document.getElementById('loginLoader');
// Show loader
loginText.style.display = 'none';
loginLoader.style.display = 'inline-block';
errorDiv.style.display = 'none';
try {
const response = await fetch(`${config.API_URL}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
});
const data = await response.json();
if (data.success) {
setAuth(data.user.token, data.user);
window.location.href = 'dashboard.html';
} else {
throw new Error(data.error || 'Login failed');
}
} catch (error) {
errorDiv.textContent = error.message;
errorDiv.style.display = 'block';
} finally {
loginText.style.display = 'inline';
loginLoader.style.display = 'none';
}
});
// Redirect if already logged in
if (isAuthenticated()) {
window.location.href = 'dashboard.html';
}
</script>
</body>
</html>