8 changed files with 358 additions and 12 deletions
-
60src/main/java/com/example/VictoriaPublicHall/controller/BookingController.java
-
48src/main/java/com/example/VictoriaPublicHall/controller/LoginController.java
-
23src/main/java/com/example/VictoriaPublicHall/controller/MainController.java
-
60src/main/java/com/example/VictoriaPublicHall/service/BookingService.java
-
34src/main/java/com/example/VictoriaPublicHall/service/LoginService.java
-
81src/main/resources/templates/admin/login.html
-
60src/main/resources/templates/admin/reports.html
-
4src/main/resources/templates/fragments/admin-navmenu.html
@ -0,0 +1,48 @@ |
|||
package com.example.VictoriaPublicHall.controller; |
|||
|
|||
import com.example.VictoriaPublicHall.service.LoginService; |
|||
import jakarta.servlet.http.HttpSession; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.ui.Model; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
|
|||
@Controller |
|||
@RequestMapping("/victoriapublichall") |
|||
|
|||
public class LoginController { |
|||
|
|||
@Autowired |
|||
private LoginService loginService; |
|||
|
|||
// Login validation |
|||
@PostMapping("/validatelogin") |
|||
public ResponseEntity<String> checkLogin(@RequestParam String usernametxt, |
|||
@RequestParam String passwordtxt, |
|||
HttpSession session) { |
|||
System.out.println("Username: " + usernametxt); |
|||
System.out.println("Password: " + passwordtxt); |
|||
|
|||
try { |
|||
String userName = loginService.validateLogin(usernametxt, passwordtxt); |
|||
System.out.println("Received username: " + usernametxt + " and password: " + passwordtxt); |
|||
System.out.println("username .....:" + userName); |
|||
if (userName != null) { |
|||
// Set user info in the session |
|||
session.setAttribute("user_name",userName ); |
|||
|
|||
return ResponseEntity.ok(userName); |
|||
} else { |
|||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid username or password"); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal server error occurred"); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package com.example.VictoriaPublicHall.service; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class LoginService { |
|||
@Autowired |
|||
private JdbcTemplate jdbcTemplate; |
|||
public String validateLogin(String usernametxt, String passwordtxt) { |
|||
|
|||
System.out.println("sql:username: '" + usernametxt + "' and pin: '" + passwordtxt + "'"); |
|||
|
|||
// SQL query |
|||
String sql = "SELECT * FROM login WHERE user_name = ? AND password = ?"; |
|||
|
|||
// Execute the query and pass mobileNo and pin as parameters |
|||
List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, usernametxt, passwordtxt); |
|||
|
|||
System.out.println("results:" + results); |
|||
|
|||
// Check if any results were found |
|||
if (!results.isEmpty()) { |
|||
Map<String, Object> login = results.get(0); |
|||
return (String) login.get("user_name"); |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
<!DOCTYPE html> |
|||
<html xmlns:th="http://www.thymeleaf.org"> |
|||
<head> |
|||
<title>Login - Victoria Public Hall</title> |
|||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"> |
|||
</head> |
|||
<body style="background: url('/images/vph_image.jpg') no-repeat center center fixed; |
|||
background-size: 100% 100%;" |
|||
class="d-flex align-items-center justify-content-center vh-100"> |
|||
|
|||
<div class="card shadow p-4" style="width: 400px; border-radius: 12px; background-color: rgba(255,255,255,0.95);"> |
|||
<div class="row m-b-20"> |
|||
<div class="col-md-12"> |
|||
<div class="text-center"> |
|||
<img src="/images/logo.png" width="60px" height="65px" alt="logo.png"> |
|||
</div> |
|||
<h5 class="text-center" style="color:#15455D;">Greater Chennai Corporation</h5> |
|||
<h5 class="text-center mb-3" style="color:#15455D;">Victoria Public Hall</h5> |
|||
<h5 class="text-center" style="color:#01A9AC;">Admin Login</h5> |
|||
</div> |
|||
</div> |
|||
|
|||
<div th:if="${error}" class="alert alert-danger text-center" th:text="${error}"></div> |
|||
|
|||
<form class="md-float-material form-material" onsubmit="return login();"> |
|||
<div class="mb-3"> |
|||
<label for="username" class="form-label">Username</label> |
|||
<input type="text" class="form-control" id="username" name="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" required> |
|||
</div> |
|||
|
|||
<div class="row mt-3"> |
|||
<div class="col-md-12 text-center"> |
|||
<button type="submit" class="btn" |
|||
style="background-color:#01A9AC; color:white; border:none; padding:8px 25px; border-radius:6px;"> |
|||
Login |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
|
|||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
|||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> |
|||
<script> |
|||
function login() { |
|||
var usernametxt = $("#username").val(); |
|||
var passwordtxt = $("#password").val(); |
|||
|
|||
$.ajax({ |
|||
type: "POST", |
|||
url: '/victoriapublichall/validatelogin', |
|||
data: { usernametxt: usernametxt, passwordtxt: passwordtxt } |
|||
}).done(function (response) { |
|||
if (response && response !== "error") { |
|||
redirectToReports(response); |
|||
} else { |
|||
Swal.fire({ icon: 'error', title: 'Oops...', text: 'Invalid Username or Password!' }); |
|||
$("#username").val(""); $("#password").val(""); |
|||
} |
|||
}).fail(function () { |
|||
Swal.fire({ icon: 'error', title: 'Error', text: 'An unexpected error occurred. Please try again later.' }); |
|||
}); |
|||
|
|||
return false; |
|||
} |
|||
|
|||
function redirectToReports(userName) { |
|||
if (userName === "admin") { |
|||
window.location.href = "/victoriapublichall/reports"; |
|||
} else { |
|||
console.error("Invalid referenceName:", userName); |
|||
} |
|||
} |
|||
</script> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,60 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> |
|||
|
|||
<head th:replace="~{fragments/user-head :: head}"> |
|||
|
|||
<title>Admin Reports</title> |
|||
<!-- DataTables CSS --> |
|||
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css"> |
|||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.2/css/buttons.bootstrap4.min.css"> |
|||
</head> |
|||
|
|||
<body> |
|||
<div th:replace="~{fragments/preloader :: div}"></div> |
|||
<div id="pcoded" class="pcoded"> |
|||
<div class="pcoded-container"> |
|||
|
|||
<!-- Top Navigation --> |
|||
<nav th:replace="~{fragments/user-nav :: nav}"></nav> |
|||
|
|||
<div class="pcoded-main-container"> |
|||
<!-- Sidebar Menu --> |
|||
<nav th:replace="~{fragments/admin-navmenu :: nav}"></nav> |
|||
|
|||
<!-- Page Wrapper --> |
|||
<div class="pcoded-wrapper"> |
|||
<div class="pcoded-content"> |
|||
<div class="pcoded-inner-content"> |
|||
<div class="main-body"> |
|||
<div class="page-wrapper"> |
|||
|
|||
<!-- Container Fix --> |
|||
<div class="container-fluid mt-4"> |
|||
<div class="row"> |
|||
<div class="col-md-12"> |
|||
<div class="card shadow-sm"> |
|||
<div class="card-body"> |
|||
|
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<!-- End Container Fix --> |
|||
|
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<footer th:replace="~{fragments/footer :: footer}"></footer> |
|||
<script th:replace="~{fragments/user-script :: script}"></script> |
|||
|
|||
<script type="text/javascript"> |
|||
|
|||
</script> |
|||
</body> |
|||
</html> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue