mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-04-05 00:44:18 -04:00
#30 Implemented environment variable to disable built-in authentication system
This commit is contained in:
12
server.js
12
server.js
@@ -30,6 +30,7 @@ const app = express();
|
||||
*/
|
||||
const random = (min, max) => Math.floor(Math.random() * (max - min)) + min;
|
||||
const voucherTypes = types(process.env.VOUCHER_TYPES || '480,0,,,;');
|
||||
const authDisabled = (process.env.DISABLE_AUTH === 'true') || false;
|
||||
|
||||
/**
|
||||
* Output logo
|
||||
@@ -44,6 +45,11 @@ voucherTypes.forEach((type, key) => {
|
||||
console.log(`[VoucherType][${key}] ${time(type.expiration)}, ${type.usage === '1' ? 'single-use' : 'multi-use'}${typeof type.upload === "undefined" && typeof type.download === "undefined" && typeof type.megabytes === "undefined" ? ', no limits' : `${typeof type.upload !== "undefined" ? `, upload bandwidth limit: ${type.upload} kb/s` : ''}${typeof type.download !== "undefined" ? `, download bandwidth limit: ${type.download} kb/s` : ''}${typeof type.megabytes !== "undefined" ? `, quota limit: ${type.megabytes} mb` : ''}`}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Log auth status
|
||||
*/
|
||||
console.log(`[AUTH] ${authDisabled ? 'Disabled!' : 'Enabled!'}`);
|
||||
|
||||
/**
|
||||
* Log controller
|
||||
*/
|
||||
@@ -105,6 +111,12 @@ app.get('/', (req, res) => {
|
||||
res.redirect(302, '/voucher');
|
||||
});
|
||||
app.get('/login', (req, res) => {
|
||||
// Check if authentication is disabled
|
||||
if(authDisabled) {
|
||||
res.redirect(302, '/voucher');
|
||||
return;
|
||||
}
|
||||
|
||||
const hour = new Date().getHours();
|
||||
const timeHeader = hour < 12 ? 'Good Morning' : hour < 18 ? 'Good Afternoon' : 'Good Evening';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user