added login function to user frontend panel
This commit is contained in:
@@ -29,7 +29,21 @@ app.listen(port, () => {
|
||||
|
||||
// -- here comes the main code --
|
||||
app.get("/", (req, res) => {
|
||||
res.render("index.ejs");
|
||||
res.render("index.ejs", { error: null });
|
||||
});
|
||||
|
||||
app.post("/login", (req, res) => {
|
||||
loginUser(req.body.username, req.body.password).then((result) => {
|
||||
if (result.success) {
|
||||
// On successful login, render the dashboard and update latestUser
|
||||
res.status(200).render("userView.ejs");
|
||||
} else {
|
||||
// On failure, re-render login page with error message
|
||||
res
|
||||
.status(401)
|
||||
.render("index.ejs", { error: result.message, });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// error handling code
|
||||
|
@@ -1 +1,66 @@
|
||||
test
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Login Page</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
</head>
|
||||
<body class="bg-dark">
|
||||
<div
|
||||
class="container d-flex justify-content-center align-items-center"
|
||||
style="min-height: 100vh"
|
||||
>
|
||||
<div class="card shadow-lg" style="width: 100%; max-width: 400px">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-center mb-4">Login</h2>
|
||||
|
||||
<% if (error) { %>
|
||||
<div class="alert alert-danger text-center" role="alert">
|
||||
<%= error %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<form action="/login" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="username"
|
||||
name="username"
|
||||
placeholder="Enter username"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
id="password"
|
||||
name="password"
|
||||
placeholder="Enter password"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
|
1
panel-mgmt_backend/views/userView.ejs
Normal file
1
panel-mgmt_backend/views/userView.ejs
Normal file
@@ -0,0 +1 @@
|
||||
userView
|
Reference in New Issue
Block a user