forked from UKSOURCE/cms.hailearning.edu.vn
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
const { readJsonFile, writeJsonFile } = require('../utils/jsonHelper');
|
|
|
|
// Hiển thị cài đặt
|
|
exports.getSettings = async (req, res) => {
|
|
try {
|
|
// Lấy cài đặt từ file content.json
|
|
const content = readJsonFile('content');
|
|
const settings = content.settings || {
|
|
siteName: 'CMS-SIMS',
|
|
description: 'Hệ thống quản lý nội dung đơn giản'
|
|
};
|
|
|
|
res.render('admin/settings', {
|
|
title: 'Cài đặt hệ thống',
|
|
settings
|
|
});
|
|
} catch (err) {
|
|
console.error(err);
|
|
req.flash('error_msg', 'Error loading settings');
|
|
res.redirect('/admin/dashboard');
|
|
}
|
|
};
|
|
|
|
// Cập nhật cài đặt
|
|
exports.updateSettings = async (req, res) => {
|
|
try {
|
|
const { siteName, description } = req.body;
|
|
|
|
// Kiểm tra dữ liệu
|
|
if (!siteName) {
|
|
req.flash('error_msg', 'Website name cannot be empty');
|
|
return res.redirect('/admin/settings');
|
|
}
|
|
|
|
// Lấy dữ liệu hiện tại
|
|
const content = readJsonFile('content');
|
|
|
|
// Cập nhật thông tin
|
|
content.settings = {
|
|
...content.settings,
|
|
siteName,
|
|
description,
|
|
updatedAt: new Date().toISOString()
|
|
};
|
|
|
|
// Lưu lại dữ liệu
|
|
writeJsonFile('content', content);
|
|
|
|
req.flash('success_msg', 'Settings updated successfully');
|
|
res.redirect('/admin/settings');
|
|
} catch (err) {
|
|
console.error(err);
|
|
req.flash('error_msg', 'Error updating settings');
|
|
res.redirect('/admin/settings');
|
|
}
|
|
};
|