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/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 } 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