From 24353eab4e283526eeffbace1b4569fc08028f5b Mon Sep 17 00:00:00 2001 From: TheLaxus Date: Fri, 21 Apr 2023 18:28:15 -0300 Subject: [PATCH 1/3] add packages --- package-lock.json | 111 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 + 2 files changed, 113 insertions(+) diff --git a/package-lock.json b/package-lock.json index 982cd1a..935e45e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "crypto": "^1.0.1", "dotenv": "^16.0.3", "express": "^4.18.2", + "handlebars": "^4.7.7", "hcaptcha": "^0.1.1", "i18n": "^0.15.1", "js_mt_rand": "^2.1.0", @@ -22,6 +23,7 @@ "mariadb": "^3.0.2", "moment": "^2.29.4", "mysql2": "^2.3.3", + "nodemailer": "^6.9.1", "request-ip": "^3.3.0", "sequelize": "^6.28.0", "uuid": "^9.0.0" @@ -556,6 +558,26 @@ "node": ">= 6" } }, + "node_modules/handlebars": { + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "dependencies": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "wordwrap": "^1.0.0" + }, + "bin": { + "handlebars": "bin/handlebars" + }, + "engines": { + "node": ">=0.4.7" + }, + "optionalDependencies": { + "uglify-js": "^3.1.4" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -919,6 +941,14 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", @@ -1018,6 +1048,19 @@ "node": ">= 0.6" } }, + "node_modules/neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + }, + "node_modules/nodemailer": { + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz", + "integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/nodemon": { "version": "2.0.20", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", @@ -1448,6 +1491,14 @@ "semver": "bin/semver.js" } }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/sqlstring": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", @@ -1525,6 +1576,18 @@ "node": ">= 0.6" } }, + "node_modules/uglify-js": { + "version": "3.17.4", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", + "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==", + "optional": true, + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -1579,6 +1642,11 @@ "@types/node": "*" } }, + "node_modules/wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==" + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -2015,6 +2083,18 @@ "is-glob": "^4.0.1" } }, + "handlebars": { + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "requires": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -2286,6 +2366,11 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" + }, "moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", @@ -2368,6 +2453,16 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + }, + "nodemailer": { + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz", + "integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==" + }, "nodemon": { "version": "2.0.20", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", @@ -2659,6 +2754,11 @@ } } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, "sqlstring": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", @@ -2715,6 +2815,12 @@ "mime-types": "~2.1.24" } }, + "uglify-js": { + "version": "3.17.4", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", + "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==", + "optional": true + }, "undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -2754,6 +2860,11 @@ "@types/node": "*" } }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==" + }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/package.json b/package.json index 10da1bf..afdf9c1 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "crypto": "^1.0.1", "dotenv": "^16.0.3", "express": "^4.18.2", + "handlebars": "^4.7.7", "hcaptcha": "^0.1.1", "i18n": "^0.15.1", "js_mt_rand": "^2.1.0", @@ -24,6 +25,7 @@ "mariadb": "^3.0.2", "moment": "^2.29.4", "mysql2": "^2.3.3", + "nodemailer": "^6.9.1", "request-ip": "^3.3.0", "sequelize": "^6.28.0", "uuid": "^9.0.0" From d6640271c71fecb2e1ddda05bc49cfe3c0fcfad8 Mon Sep 17 00:00:00 2001 From: Lucas Barbosa Date: Tue, 23 Jan 2024 16:31:16 -0300 Subject: [PATCH 2/3] token never expire --- src/controllers/LoginController.js | 7 +++++-- src/controllers/RegisterController.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/controllers/LoginController.js b/src/controllers/LoginController.js index ae1d0b1..f9f3b1a 100644 --- a/src/controllers/LoginController.js +++ b/src/controllers/LoginController.js @@ -17,9 +17,12 @@ var mt = require('../modules/mt_rand'); const i18n = require('../translation/i18n'); function generateToken(params = {}) { + /* return jwt.sign(params, auth.jwt_secret_key, { - expiresIn: '1d' // 1day - }); + expiresIn: '1d' // 1 dia + });*/ + + return jwt.sign(params, auth.jwt_secret_key); //never expire } module.exports = { diff --git a/src/controllers/RegisterController.js b/src/controllers/RegisterController.js index 7f8ef07..95c61a4 100644 --- a/src/controllers/RegisterController.js +++ b/src/controllers/RegisterController.js @@ -13,9 +13,12 @@ const functions = require('../modules/functions'); const { verify } = require('hcaptcha'); function generateToken(params = {}) { + /* return jwt.sign(params, auth.jwt_secret_key, { - expiresIn: '1d' // 1day - }); + expiresIn: '1d' // 1 dia + });*/ + + return jwt.sign(params, auth.jwt_secret_key); //never expire } From d3910ea4a9b0e935567122c706c0d608f779aba9 Mon Sep 17 00:00:00 2001 From: Lucas Barbosa Date: Mon, 5 Feb 2024 22:48:11 -0300 Subject: [PATCH 3/3] token never expire, send form, user online --- src/controllers/ArticlesController.js | 42 +++++++++++++++++++++++++-- src/controllers/HomeController.js | 2 +- src/translation/locales/en.json | 7 ++++- src/translation/locales/pt.json | 6 +++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/controllers/ArticlesController.js b/src/controllers/ArticlesController.js index 0097b1e..edd96ca 100644 --- a/src/controllers/ArticlesController.js +++ b/src/controllers/ArticlesController.js @@ -1,7 +1,6 @@ const sequelize = require('sequelize'); const auth = require('../config/auth.json'); const bcrypt = require('bcryptjs'); -const PlayerModel = require('../database/models/Player'); const config = require('config'); const db = require('../database'); const moment = require('moment'); @@ -10,7 +9,7 @@ const jwt = require('jsonwebtoken'); const functions = require('../modules/functions'); const i18n = require('../translation/i18n'); -const ArticlesModel = require('../database/models/Articles'); +const FormArticleModal = require('../database/models/FormArticle'); module.exports = { @@ -592,6 +591,45 @@ module.exports = { } catch (error) { return res.status(500).json({ error }); } + }, + + async sendForm(req, res) { + + + var success = []; + + + const { articleId, userId, participants, link, message } = req.body; + const checkLimitForm = await FormArticleModal.findAndCountAll({ where: { article_id: articleId, user_id: userId } }); + + if (!participants || !link) { + return res.status(200).json({ + error: true, + status_code: 400, + message: i18n.__('formParticipantsOrLinkRequired') + }); + } else if (checkLimitForm.count >= 3) { + return res.status(200).json({ + error: true, + status_code: 400, + message: i18n.__('formCheckLimit') + }); + } else { + await FormArticleModal.create({ article_id: articleId, user_id: userId, usernames: participants, timestamp: moment().unix(), link: link, message: message }) + .then(() => { + return res.status(200).json({ + status_code: 200, + message: i18n.__('formSendSuccess') + }); + }).catch(() => { + return res.status(200).json({ + error: true, + status_code: 400, + message: i18n.__('formErrorUnknow') + }); + }).finally(() => {}) + } + } } diff --git a/src/controllers/HomeController.js b/src/controllers/HomeController.js index 553e475..9aaa7d2 100644 --- a/src/controllers/HomeController.js +++ b/src/controllers/HomeController.js @@ -220,7 +220,7 @@ module.exports = { type: sequelize.QueryTypes.SELECT }); - let usersOnline = JSON.stringify(count[0].active_players + 23); + let usersOnline = JSON.stringify(count[0].active_players); return res.status(200).json({ count: usersOnline }); diff --git a/src/translation/locales/en.json b/src/translation/locales/en.json index 2c9cf78..a839d99 100644 --- a/src/translation/locales/en.json +++ b/src/translation/locales/en.json @@ -14,5 +14,10 @@ "articlesSectionsThisMont": "Esse mês", "articlesSectionsLastMonth": "Último mês", "articlesSectionsOldest": "Antigo", - "getNewsNotFound": "getNewsNotFound" + "getNewsNotFound": "getNewsNotFound", + "formCheckLimit": "Submission limit reached", + "formSendSuccess": "Form submitted successfully! Thank you for participating!", + "formErrorUnknow": "Unknown error, please try again.", + "formParticipantsOrLinkRequired": "Participant or link is required to submit the form" + } \ No newline at end of file diff --git a/src/translation/locales/pt.json b/src/translation/locales/pt.json index 42193e3..4ebf433 100644 --- a/src/translation/locales/pt.json +++ b/src/translation/locales/pt.json @@ -14,5 +14,9 @@ "articlesSectionsThisMont": "Esse mês", "articlesSectionsLastMonth": "Último mês", "articlesSectionsOldest": "Antigo", - "getNewsNotFound": "getNewsNotFound" + "getNewsNotFound": "getNewsNotFound", + "formParticipantsOrLinkRequired": "O participante ou o link é obrigatório para enviar o formulário", + "formCheckLimit": "Limite de envios antigidos", + "formSendSuccess": "Formulário enviado com sucesso! Obrigado por participar!", + "formErrorUnknow": "Erro desconhecido, tente novamente." } \ No newline at end of file