mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-07-19 00:42:16 -05:00
Server now sends confirmation emails to the provided email address. The values can not yet be validated, but they are stored so validation can be added at any time. Added Winston for event logging. Winston has a log level system that merges certain log types into the same file. Maybe we should use a custom logger solution? Registration now works (was not working for me), with added reCaptcha protection, password validation, and the storing of usernames/email validation values. Also changed the PID to a number, cuz it's a number
71 lines
1.3 KiB
JavaScript
71 lines
1.3 KiB
JavaScript
/*
|
|
|
|
util.js -
|
|
small commonly used utilities
|
|
|
|
*/
|
|
|
|
const fs = require('fs-extra');
|
|
const logger = require('winston');
|
|
|
|
// shows 404 template. takes express response object
|
|
function send404(res) {
|
|
res.status(404).send('404');
|
|
}
|
|
|
|
function templateReadyUser(req) {
|
|
// normal user logged in
|
|
const isLoggedIn = req.user ? req.user.role != 'admin' : false;
|
|
const user = req.user;
|
|
return {
|
|
isLoggedIn,
|
|
user
|
|
};
|
|
}
|
|
|
|
// Returns a list of possible locales:
|
|
/*
|
|
* [
|
|
* {
|
|
* region: 'US',
|
|
* language: 'en',
|
|
* display: 'American English',
|
|
* flag_id: 1 // I dunno maybe we display a local list that also displays flags?
|
|
* }
|
|
* ]
|
|
*
|
|
*/
|
|
function getLocales() {
|
|
return [];
|
|
}
|
|
|
|
// Returns a locale
|
|
function getLocale(region, language) {
|
|
const path = `${__dirname}/../locales/${region}_${language}.json`;
|
|
|
|
if (fs.pathExistsSync(path)) {
|
|
return require(path);
|
|
}
|
|
|
|
logger.log('warn', `Could not find locale ${region}_${language}! Loading default`);
|
|
|
|
return getDefaultLocale();
|
|
}
|
|
|
|
// Returns the default locale
|
|
function getDefaultLocale(locale='default') {
|
|
return require(`${__dirname}/../locales/${locale}.json`);
|
|
}
|
|
|
|
function generateRandomInt(length = 4) {
|
|
return Math.floor(Math.pow(10, length-1) + Math.random() * 9 * Math.pow(10, length-1));
|
|
}
|
|
|
|
module.exports = {
|
|
send404,
|
|
templateReadyUser,
|
|
getLocales,
|
|
getLocale,
|
|
getDefaultLocale,
|
|
generateRandomInt
|
|
}; |