forked from UKSOURCE/cms.hailearning.edu.vn
first commit
This commit is contained in:
347
routes/admin.js
Normal file
347
routes/admin.js
Normal file
@@ -0,0 +1,347 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const { ensureAuthenticated } = require("../middleware/auth");
|
||||
const dashboardController = require("../controllers/dashboardController");
|
||||
const uploadController = require("../controllers/uploadController");
|
||||
const homeController = require("../controllers/homeController");
|
||||
const aboutController = require("../controllers/aboutController");
|
||||
const headerController = require("../controllers/headerController");
|
||||
const footerController = require("../controllers/footerController");
|
||||
const aboutUsController = require("../controllers/aboutUsController");
|
||||
const formController = require("../controllers/formController");
|
||||
const contactController = require("../controllers/contactController");
|
||||
const campLocationController = require("../controllers/campLocationController");
|
||||
const pageController = require("../controllers/pageController");
|
||||
const settingController = require("../controllers/settingController");
|
||||
const faqController = require("../controllers/faqController"); // Thêm import này
|
||||
const termsController = require("../controllers/termsController");
|
||||
const travelController = require("../controllers/travelController");
|
||||
|
||||
const { upload, uploadVideo, convertToWebp } = require("../middleware/upload");
|
||||
const safetyController = require("../controllers/safetyController");
|
||||
const insuranceController = require("../controllers/insuranceController");
|
||||
|
||||
const activityController = require("../controllers/activityController");
|
||||
const bookingSubmissionController = require("../controllers/bookingSubmissionController");
|
||||
|
||||
// Dashboard
|
||||
router.get("/dashboard", ensureAuthenticated, dashboardController.getDashboard);
|
||||
|
||||
// Home
|
||||
router.get("/home", ensureAuthenticated, homeController.index);
|
||||
router.post("/home/update", ensureAuthenticated, homeController.update);
|
||||
|
||||
// Middleware chuẩn hóa code
|
||||
router.param("code", (req, res, next, code) => {
|
||||
req.params.code = code.toUpperCase();
|
||||
next();
|
||||
});
|
||||
|
||||
// About
|
||||
router.get("/about", ensureAuthenticated, aboutController.index);
|
||||
router.post("/about/update", ensureAuthenticated, aboutController.update);
|
||||
|
||||
// AboutUs admin CRUD
|
||||
router.get("/about-us", ensureAuthenticated, aboutUsController.index);
|
||||
router.get(
|
||||
"/about-us/create",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.createForm
|
||||
);
|
||||
router.post("/about-us/create", ensureAuthenticated, aboutUsController.create);
|
||||
router.get(
|
||||
"/about-us/:id/edit",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.editForm
|
||||
);
|
||||
router.post(
|
||||
"/about-us/:id/update",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.update
|
||||
);
|
||||
router.post(
|
||||
"/about-us/:id/delete",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.delete
|
||||
);
|
||||
router.get(
|
||||
"/about-us/:id/preview",
|
||||
ensureAuthenticated,
|
||||
aboutUsController.preview
|
||||
);
|
||||
|
||||
// Booking admin CRUD removed
|
||||
|
||||
// Form Management
|
||||
router.get("/form", ensureAuthenticated, formController.index);
|
||||
router.post(
|
||||
"/form/update",
|
||||
ensureAuthenticated,
|
||||
formController.updateDefaultForm
|
||||
);
|
||||
|
||||
// Upload routes
|
||||
router.get("/upload", ensureAuthenticated, (req, res) => {
|
||||
res.render("admin/upload/index", {
|
||||
layout: "layouts/admin",
|
||||
title: "Quản lý Upload Ảnh",
|
||||
user: req.session.user,
|
||||
});
|
||||
});
|
||||
router.post(
|
||||
"/upload/image",
|
||||
ensureAuthenticated,
|
||||
upload.single("image"),
|
||||
// convertToWebp, // Disabled to keep original image format (JPG/PNG)
|
||||
uploadController.uploadImage
|
||||
);
|
||||
router.post(
|
||||
"/upload/video",
|
||||
ensureAuthenticated,
|
||||
uploadVideo.single("video"),
|
||||
uploadController.uploadVideo
|
||||
);
|
||||
router.post(
|
||||
"/upload/update-path",
|
||||
ensureAuthenticated,
|
||||
uploadController.updateImagePath
|
||||
);
|
||||
router.post(
|
||||
"/upload/delete",
|
||||
ensureAuthenticated,
|
||||
uploadController.deleteImage
|
||||
);
|
||||
|
||||
// Header routes
|
||||
router.get("/header", ensureAuthenticated, headerController.index);
|
||||
router.post("/header/update", ensureAuthenticated, headerController.update);
|
||||
router.post(
|
||||
"/header/update-menu",
|
||||
ensureAuthenticated,
|
||||
headerController.updateMenu
|
||||
);
|
||||
router.get(
|
||||
"/header/menu-tree",
|
||||
ensureAuthenticated,
|
||||
headerController.getMenuTree
|
||||
);
|
||||
router.get(
|
||||
"/header/programmes/:menuId",
|
||||
ensureAuthenticated,
|
||||
headerController.getProgrammesByMenuId
|
||||
);
|
||||
router.get(
|
||||
"/header/menu-item/:menuId",
|
||||
ensureAuthenticated,
|
||||
headerController.getMenuItem
|
||||
);
|
||||
router.get("/header/data", ensureAuthenticated, headerController.getHeaderData);
|
||||
|
||||
// Footer routes
|
||||
router.get("/footer", ensureAuthenticated, footerController.index);
|
||||
router.post("/footer/update", ensureAuthenticated, footerController.update);
|
||||
router.get("/footer/data", ensureAuthenticated, footerController.getFooterData);
|
||||
|
||||
// Contact routes
|
||||
router.get("/contact", ensureAuthenticated, contactController.index);
|
||||
router.post("/contact/update", ensureAuthenticated, contactController.update);
|
||||
router.get(
|
||||
"/contact/data",
|
||||
ensureAuthenticated,
|
||||
contactController.getContactData
|
||||
);
|
||||
|
||||
// Activity CRUD routes
|
||||
router.get("/activity", ensureAuthenticated, activityController.index);
|
||||
router.get(
|
||||
"/activity/create",
|
||||
ensureAuthenticated,
|
||||
activityController.createForm
|
||||
);
|
||||
router.post("/activity/create", ensureAuthenticated, activityController.create);
|
||||
// Update filters (place before any parameterized /activity/:id routes to avoid route collision)
|
||||
router.post(
|
||||
"/activity/filters/update",
|
||||
ensureAuthenticated,
|
||||
activityController.updateFilters
|
||||
);
|
||||
// Update hero (global hero section for activities)
|
||||
router.post(
|
||||
"/activity/hero/update",
|
||||
ensureAuthenticated,
|
||||
activityController.updateHero
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/edit",
|
||||
ensureAuthenticated,
|
||||
activityController.editForm
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/update",
|
||||
ensureAuthenticated,
|
||||
activityController.update
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/delete",
|
||||
ensureAuthenticated,
|
||||
activityController.delete
|
||||
);
|
||||
router.post(
|
||||
"/activity/:id/toggle-status",
|
||||
ensureAuthenticated,
|
||||
activityController.toggleStatus
|
||||
);
|
||||
// Update display order
|
||||
router.post(
|
||||
"/activity/update-order",
|
||||
ensureAuthenticated,
|
||||
activityController.updateOrder
|
||||
);
|
||||
|
||||
// Booking submissions routes
|
||||
router.get(
|
||||
"/activity/:id/bookings/count",
|
||||
ensureAuthenticated,
|
||||
activityController.getBookingCount
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/bookings",
|
||||
ensureAuthenticated,
|
||||
activityController.getBookingSubmissions
|
||||
);
|
||||
router.get(
|
||||
"/activity/:id/bookings/export",
|
||||
ensureAuthenticated,
|
||||
activityController.exportBookingData
|
||||
);
|
||||
// Export all bookings (across all activities)
|
||||
router.get(
|
||||
"/bookings/export-all",
|
||||
ensureAuthenticated,
|
||||
activityController.exportAllBookingsData
|
||||
);
|
||||
// Update booking submission
|
||||
router.put(
|
||||
"/bookings/:bookingId",
|
||||
ensureAuthenticated,
|
||||
bookingSubmissionController.updateBookingSubmission
|
||||
);
|
||||
// Delete booking submission
|
||||
router.delete(
|
||||
"/bookings/:bookingId",
|
||||
ensureAuthenticated,
|
||||
bookingSubmissionController.deleteBookingSubmission
|
||||
);
|
||||
|
||||
// Update filters
|
||||
|
||||
// Preview activity
|
||||
router.get(
|
||||
"/activity/:id/preview",
|
||||
ensureAuthenticated,
|
||||
activityController.preview
|
||||
);
|
||||
|
||||
// FAQ routes - Thêm vào đây
|
||||
router.get("/faq", ensureAuthenticated, faqController.index);
|
||||
router.post("/faq/update", ensureAuthenticated, faqController.update);
|
||||
router.get("/faq/data", ensureAuthenticated, faqController.getFAQData);
|
||||
router.get("/faq/api", faqController.api);
|
||||
|
||||
// API routes cho quản lý FAQ items (AJAX calls)
|
||||
router.post("/faq/api/add-faq", ensureAuthenticated, faqController.addFAQ);
|
||||
router.put("/faq/api/update-faq-item/:sectionId/:faqId", ensureAuthenticated, faqController.updateFAQItem);
|
||||
router.delete("/faq/api/delete-faq-item/:sectionId/:faqId", ensureAuthenticated, faqController.deleteFAQItem);
|
||||
router.get("/terms-conditions", ensureAuthenticated, termsController.index);
|
||||
router.post("/terms/update", ensureAuthenticated, termsController.update);
|
||||
router.get("/terms/data", ensureAuthenticated, termsController.getTermsData);
|
||||
router.get("/terms/api", termsController.api);
|
||||
router.get("/terms/seed", ensureAuthenticated, termsController.seed);
|
||||
|
||||
// Travel routes
|
||||
router.get("/travel", ensureAuthenticated, travelController.index);
|
||||
router.post("/travel/update", ensureAuthenticated, travelController.update);
|
||||
router.post("/travel/preview", ensureAuthenticated, travelController.preview);
|
||||
router.get("/travel/data", ensureAuthenticated, travelController.getTravelData);
|
||||
router.get("/travel/api", travelController.api);
|
||||
router.get("/travel/seed", ensureAuthenticated, travelController.seed);
|
||||
|
||||
// API routes cho quản lý FAQ sections (AJAX calls)
|
||||
router.post("/faq/api/add-section", ensureAuthenticated, faqController.addFAQSection);
|
||||
router.put("/faq/api/update-section/:sectionId", ensureAuthenticated, faqController.updateFAQSection);
|
||||
router.delete("/faq/api/delete-section/:sectionId", ensureAuthenticated, faqController.deleteFAQSection);
|
||||
router.post("/faq/api/reorder-sections", ensureAuthenticated, faqController.reorderFAQSection);
|
||||
|
||||
// API routes cho sidebar navigation (AJAX calls)
|
||||
router.put("/faq/api/update-sidebar", ensureAuthenticated, faqController.updateSidebarNav);
|
||||
|
||||
// Safety routes
|
||||
router.get("/safety", ensureAuthenticated, safetyController.index);
|
||||
router.post("/safety/update", ensureAuthenticated, safetyController.update);
|
||||
// Camp Location routes
|
||||
router.get("/camp-location", ensureAuthenticated, campLocationController.index);
|
||||
router.post("/camp-location/update", ensureAuthenticated, campLocationController.update);
|
||||
|
||||
//Insurance routes
|
||||
router.get("/insurance", ensureAuthenticated, insuranceController.index);
|
||||
router.post("/insurance/update", ensureAuthenticated, insuranceController.update);
|
||||
// Test Image Paths route
|
||||
router.get("/test-images", ensureAuthenticated, (req, res) => {
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const campLocationData = require('../data/camp-location.json');
|
||||
|
||||
// Collect all image paths
|
||||
const imagePaths = [];
|
||||
|
||||
// Camps images
|
||||
if (campLocationData.camps) {
|
||||
campLocationData.camps.forEach(camp => {
|
||||
if (camp.image) {
|
||||
imagePaths.push({
|
||||
type: 'Camp',
|
||||
name: camp.title,
|
||||
path: camp.image,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', camp.image))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Locations images
|
||||
if (campLocationData.locations) {
|
||||
campLocationData.locations.forEach(location => {
|
||||
if (location.imageSrc) {
|
||||
imagePaths.push({
|
||||
type: 'Location',
|
||||
name: location.title,
|
||||
path: location.imageSrc,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', location.imageSrc))
|
||||
});
|
||||
}
|
||||
|
||||
// Program images
|
||||
if (location.programOptions) {
|
||||
location.programOptions.forEach(program => {
|
||||
if (program.imageSrc) {
|
||||
imagePaths.push({
|
||||
type: 'Program',
|
||||
name: program.title,
|
||||
path: program.imageSrc,
|
||||
exists: fs.existsSync(path.join(__dirname, '../public', program.imageSrc))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
res.render('admin/test-images', {
|
||||
layout: 'layouts/admin',
|
||||
title: 'Test Image Paths',
|
||||
images: imagePaths,
|
||||
user: req.session.user
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
46
routes/auth.js
Normal file
46
routes/auth.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const ADMIN_USERNAME = 'admin';
|
||||
const ADMIN_PASSWORD = 'admin1234';
|
||||
|
||||
// Login page
|
||||
router.get('/login', (req, res) => {
|
||||
if (req.session.isAuthenticated) {
|
||||
return res.redirect('/admin/dashboard');
|
||||
}
|
||||
|
||||
res.render('auth/login', {
|
||||
title: 'Login',
|
||||
layout: false
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/login', async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
if (username === ADMIN_USERNAME && password === ADMIN_PASSWORD) {
|
||||
req.session.user = {
|
||||
username: ADMIN_USERNAME,
|
||||
email: 'admin@ggcamp.org',
|
||||
name: 'Administrator',
|
||||
role: 'admin'
|
||||
};
|
||||
req.session.isAuthenticated = true;
|
||||
req.flash('success_msg', 'Login successful');
|
||||
res.redirect('/admin/dashboard');
|
||||
} else {
|
||||
req.flash('error_msg', 'Invalid username or password');
|
||||
res.redirect('/auth/login');
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/logout', (req, res) => {
|
||||
req.session.destroy((err) => {
|
||||
if (err) {
|
||||
console.error('Error when logout:', err);
|
||||
}
|
||||
res.redirect('/');
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
127
routes/index.js
Normal file
127
routes/index.js
Normal file
@@ -0,0 +1,127 @@
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const router = express.Router();
|
||||
const homeController = require("../controllers/homeController");
|
||||
const aboutController = require("../controllers/aboutController");
|
||||
const aboutUsController = require("../controllers/aboutUsController");
|
||||
const headerController = require("../controllers/headerController");
|
||||
const footerController = require("../controllers/footerController");
|
||||
const contactController = require("../controllers/contactController");
|
||||
const faqController = require("../controllers/faqController");
|
||||
|
||||
const safetyController = require("../controllers/safetyController");
|
||||
const campLocationController = require("../controllers/campLocationController");
|
||||
// Booking flow removed
|
||||
|
||||
const insuranceController= require("../controllers/insuranceController");
|
||||
const termsController = require("../controllers/termsController"); // <-- IMPORT ĐÃ CÓ
|
||||
const activityController = require("../controllers/activityController");
|
||||
const travelController = require("../controllers/travelController");
|
||||
const bookingSubmissionController = require("../controllers/bookingSubmissionController");
|
||||
|
||||
// Trang chủ
|
||||
router.get("/", (req, res) => {
|
||||
res.render("index", {
|
||||
title: "Welcome",
|
||||
layout: "layouts/main",
|
||||
});
|
||||
});
|
||||
|
||||
// API để lấy dữ liệu trang chủ
|
||||
router.get("/api/home", homeController.api);
|
||||
|
||||
// API để lấy dữ liệu about
|
||||
router.get("/api/about", aboutController.api);
|
||||
|
||||
// Public about-us page and API (aboutUs.json flow)
|
||||
router.get("/about-us", aboutUsController.page);
|
||||
// Return a list/array of AboutUs records for frontend consumption
|
||||
router.get("/api/about-us", aboutUsController.apiList);
|
||||
|
||||
// Header API route
|
||||
router.get("/api/header", headerController.api);
|
||||
|
||||
// Menu Tree API route (for frontend)
|
||||
router.get("/api/menu-tree", headerController.getMenuTreeAPI);
|
||||
|
||||
// Footer API route
|
||||
router.get("/api/footer", footerController.api);
|
||||
|
||||
// Contact API route
|
||||
router.get("/api/contact", contactController.api);
|
||||
|
||||
router.get("/api/faq", faqController.api);
|
||||
// Safety API route
|
||||
router.get("/api/safety", safetyController.api);
|
||||
// Activity API routes
|
||||
router.get("/api/activities", activityController.api);
|
||||
router.get("/api/activities/:id", activityController.apiDetail);
|
||||
|
||||
// Camp Location API route
|
||||
router.get("/api/camp-location", campLocationController.api);
|
||||
// Booking routes removed
|
||||
// Insurance APi route
|
||||
router.get("/api/insurance", insuranceController.api)
|
||||
|
||||
|
||||
router.get("/api/terms", termsController.api);
|
||||
|
||||
// Travel public page and API
|
||||
router.get("/travel", async (req, res) => {
|
||||
try {
|
||||
const Travel = require("../models/travel");
|
||||
const travel = await Travel.findOne();
|
||||
|
||||
if (!travel) {
|
||||
return res.status(404).render("errors/404", {
|
||||
title: "Page Not Found",
|
||||
message: "Travel information not found",
|
||||
});
|
||||
}
|
||||
|
||||
res.render("page/travel", {
|
||||
title: travel.page.title,
|
||||
data: travel.toObject(),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error loading travel page:", error);
|
||||
res.status(500).render("errors/500", {
|
||||
title: "Server Error",
|
||||
message: "Error loading travel page",
|
||||
});
|
||||
}
|
||||
});
|
||||
router.get("/api/travel", travelController.api);
|
||||
|
||||
// Booking submission APIs (public endpoints)
|
||||
router.post("/api/booking/submit", bookingSubmissionController.submitBooking);
|
||||
router.get("/api/activity/:activityId/sessions", bookingSubmissionController.getAvailableSessions);
|
||||
router.get("/api/activity/:activityId/session/:sessionId/availability", bookingSubmissionController.getSessionAvailability);
|
||||
|
||||
// New API for creating bookings directly into camp sessions (by program)
|
||||
router.post(
|
||||
"/api/camps/:program/sessions/:sessionId/bookings",
|
||||
activityController.createSessionBookingByProgram
|
||||
);
|
||||
router.get(
|
||||
"/api/camps/:program/sessions/:sessionId/bookings",
|
||||
activityController.getSessionBookingsByProgram
|
||||
);
|
||||
// Keep admin-style update/delete by activityId (protected) if needed
|
||||
router.put("/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId", activityController.updateSessionBooking);
|
||||
router.delete("/api/camps/:activityId/sessions/:sessionId/bookings/:bookingId", activityController.deleteSessionBooking);
|
||||
|
||||
// Demo booking form
|
||||
router.get("/demo/booking-form", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../views/demo/booking-form.html'));
|
||||
});
|
||||
|
||||
// Demo session booking API
|
||||
router.get("/demo/session-booking-api", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../views/demo/session-booking-api.html'));
|
||||
});
|
||||
|
||||
// // API route cho blog detail
|
||||
// router.get('/api/blog-detail', blogDetailController.api);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user