mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-04-05 08:54:17 -04:00
Updated kiosk.json with new translation strings. Updated info.js to reflect the multiple kiosk voucher types. Deprecated the KIOSK_VOUCHER_TYPE environment variable. Implemented the KIOSK_VOUCHER_TYPES environment variable with support for multiple voucher types. Moved the kiosk images (logo.png and bg.jpg) to a kiosk image sub-folder. Redesign of the kiosk.ejs language selector to provide space for custom images. Implemented voucher types within kiosk.ejs. Utilize the bytes converter within voucher.ejs to reformat bytes labels. Updated the docker-compose.yml. Updated the README.md. Implemented /kiosk custom assets overrides. Implemented a type check for the voucher types from kiosk requests
This commit is contained in:
20
server.js
20
server.js
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Import base packages
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const crypto = require('crypto');
|
||||
const express = require('express');
|
||||
@@ -88,6 +89,13 @@ app.use((req, res, next) => {
|
||||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
* Override kiosk images dir if available
|
||||
*/
|
||||
if(fs.existsSync('/kiosk')) {
|
||||
app.use('/images/kiosk', express.static('/kiosk'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve static public dir
|
||||
*/
|
||||
@@ -155,6 +163,9 @@ if(variables.serviceWeb) {
|
||||
baseUrl: req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : '',
|
||||
error: req.flashMessage.type === 'error',
|
||||
error_text: req.flashMessage.message || '',
|
||||
timeConvert: time,
|
||||
bytesConvert: bytes,
|
||||
voucher_types: types(variables.kioskVoucherTypes),
|
||||
kiosk_name_required: variables.kioskNameRequired
|
||||
});
|
||||
});
|
||||
@@ -207,8 +218,15 @@ if(variables.serviceWeb) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const typeCheck = (variables.kioskVoucherTypes).split(';').includes(req.body['voucher-type']);
|
||||
|
||||
if (!typeCheck) {
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Unknown Type!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/kiosk`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create voucher code
|
||||
const voucherCode = await unifi.create(types(variables.kioskVoucherType, true), 1, variables.kioskNameRequired ? req.body['voucher-note'] : null).catch((e) => {
|
||||
const voucherCode = await unifi.create(types(req.body['voucher-type'], true), 1, variables.kioskNameRequired ? req.body['voucher-note'] : null).catch((e) => {
|
||||
res.cookie('flashMessage', JSON.stringify({type: 'error', message: e}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/kiosk`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user