Skip to content

Commit

Permalink
Merge pull request #24 from thefirstspine/next
Browse files Browse the repository at this point in the history
Release 1.11.0
  • Loading branch information
thefirstspine authored Jul 9, 2020
2 parents 1dca551 + 0c3afcc commit c9c5527
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/controllers/CodesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
// Add the rewards to the user
const promises = Object.keys(codeEntity.loots).map((lootName) => {
return fetch(
`${process.env.ARENA_URL}/wizzard/reward/${req.user_id}`,
`${process.env.ARENA_URL}/wizard/${req.user_id}/reward`,
{
method: 'POST',
body: JSON.stringify({
Expand Down
87 changes: 87 additions & 0 deletions api/controllers/ReportController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* RulesController
*
* @description :: Server-side actions for handling incoming requests.
* @help :: See https://sailsjs.com/docs/concepts/actions
*/

module.exports = {

async index(req, res) {
const id = parseInt(req.param('id'));
if (id === 0 || isNaN(id)) {
return res.notFound();
}

return res.view(
'pages/report.ejs',
{
...await sails.helpers.layoutConfig(req.user_id),
errors: [],
}
);
},

async report(req, res) {
const id = parseInt(req.param('id'));
if (id === 0 || isNaN(id)) {
return res.notFound();
}

const reason = req.body.reason;
const details = req.body.details;

const errors = [];
if (!['cheat', 'inappropriate-behavior-insults', 'harassment-or-intimidation'].includes(reason)) {
errors.push('report.errorInvalidReason');
}
if (typeof(details) !== "string" || details.length < 10) {
errors.push('report.errorMoreDetails');
}

if (errors.length) {
return res.view(
'pages/report.ejs',
{
...await sails.helpers.layoutConfig(req.user_id),
errors,
reason,
details,
}
);
}

const nodemailer = require('nodemailer');
const smtpTransport = require('nodemailer-smtp-transport');
const transport = nodemailer.createTransport(smtpTransport(process.env.SMTP_TRANSPORT));
var mailOptions = {
from: 'TFS report abuse form <[email protected]>', // sender address
to: process.env.REPORT_TO, // list of receivers
subject: 'Someone submitted an abuse ticket', // Subject line
text: `Player ID of sumbmitter: "${req.user_id}"
Targetted player ID: "${id}"
Reason: ${reason}
Details: ${details}
`, // plaintext body
};

transport.sendMail(mailOptions, function(error, info){
if(error) {
console.log(error);
} else {
console.log('Message sent: ' , info);
}
});

return res.view(
'pages/report.ejs',
{
...await sails.helpers.layoutConfig(req.user_id),
message: 'report.messageReportSent',
}
);
},

};
4 changes: 2 additions & 2 deletions api/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ module.exports = {


const response = await fetch(
`${process.env.ARENA_URL}/wizzard`,
`${process.env.ARENA_URL}/wizard`,
{
method: 'GET',
headers: {
Expand Down Expand Up @@ -277,7 +277,7 @@ module.exports = {
const errors = [];

const response = await fetch(
`${process.env.ARENA_URL}/wizzard`,
`${process.env.ARENA_URL}/wizard`,
{
method: 'GET',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion api/policies/is-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ module.exports = async function (req, res, proceed) {

//--•
// Otherwise, this request did not come from a logged-in user.
return res.forbidden();
return res.forbidden('not-admin');

};
2 changes: 1 addition & 1 deletion api/policies/is-logged-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ module.exports = async function (req, res, proceed) {

//--•
// Otherwise, this request did not come from a logged-in user.
return res.forbidden();
return res.forbidden('not-logged-in');

};
73 changes: 73 additions & 0 deletions api/responses/forbidden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* forbidden.js
*
* A custom response.
*
* Example usage:
* ```
* return res.forbidden();
* // -or-
* return res.forbidden(optionalData);
* ```
*
* Or with actions2:
* ```
* exits: {
* somethingHappened: {
* responseType: 'forbidden'
* }
* }
* ```
*
* ```
* throw 'somethingHappened';
* // -or-
* throw { somethingHappened: optionalData }
* ```
*/

const { option } = require("grunt");

module.exports = function forbidden(optionalData) {

// Get access to `req` and `res`
const req = this.req;
const res = this.res;

// Define the status code to send in the response.
var statusCodeToSet = 403;

// If no data was provided, use res.sendStatus().
if (optionalData === undefined) {
sails.log.info('Ran custom response: res.forbidden()');
return res.sendStatus(statusCodeToSet);
}
// Else if the provided data is an Error instance, if it has
// a toJSON() function, then always run it and use it as the
// response body to send. Otherwise, send down its `.stack`,
// except in production use res.sendStatus().
else if (_.isError(optionalData)) {
sails.log.info('Custom response `res.forbidden()` called with an Error:', optionalData);

// If the error doesn't have a custom .toJSON(), use its `stack` instead--
// otherwise res.json() would turn it into an empty dictionary.
// (If this is production, don't send a response body at all.)
if (!_.isFunction(optionalData.toJSON)) {
if (process.env.NODE_ENV === 'production') {
return res.sendStatus(statusCodeToSet);
}
else {
return res.status(statusCodeToSet).send(optionalData.stack);
}
}
}
// Redirect in case of 'not-logged-in' reason
else if (optionalData === 'not-logged-in') {
return res.redirect(`/login?redirect=${req.originalUrl.substr(1)}`);
}
// Set status code and send response data.
else {
return res.status(statusCodeToSet).send(optionalData);
}

};
22 changes: 22 additions & 0 deletions config/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,27 @@
"error-length": "Password must be at least 8 characters long.",
"error-unkown": "Password change failed.",
"message-passwordChanged": "Password has been changed."
},
"report": {
"title": "Report a player",
"form": "Reporting form",
"reason": "Reason for reporting",
"chose": "Choose...",
"cheat": "Cheat",
"inappropriate-behavior-insults": "Inappropriate behavior, insults",
"harassment-or-intimidation": "Harassment or intimidation",
"moreDetails": "Give us more details about your report",
"detailsPlaceholder": "Be as specific as possible, with timetables and copies of your transcripts. We will not be able to take the necessary measures if the slightest doubt remains.",
"reportPlayer": "Report this player",
"sanctions": "The sanctions applied",
"sanctionsText": "Here are the floor sanctions we apply. If we find aggravating circumstances (installing spyware on another player's client, for example), we reserve the right to add curses or apply a permanent ban immediately.",
"penalty": "Penalty without recurrence",
"penaltyRecurrence": "Penalty if recurrence",
"penaltyRecurrence2": "Penalty for second recidivism",
"curse": "Curse",
"banishment": "Banishment",
"errorInvalidReason": "Invalid reason",
"errorMoreDetails": "Please give more details",
"messageReportSent": "Your report was sent!"
}
}
22 changes: 22 additions & 0 deletions config/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,27 @@
"error-length": "Le mot de passe doit avoir au moins 8 caractères.",
"error-unkown": "Le changement de mot de passe a échoué.",
"message-passwordChanged": "Le mot de passe a été modifié."
},
"report": {
"title": "Signaler un joueur",
"form": "Formulaire de signalement",
"reason": "Raison du signalement",
"chose": "Choisissez...",
"cheat": "Triche",
"inappropriate-behavior-insults": "Comportement inapproprié, injures",
"harassment-or-intimidation": "Harcèlement ou intimidation",
"moreDetails": "Donnez-nous plus de détails à propos de votre signalement",
"detailsPlaceholder": "Soyez le plus précis possible, avec des horaires et des copies de vos transcriptions. Nous ne pourrons pas prendre les mesures nécessaires si le moindre doute subsiste.",
"reportPlayer": "Signaler ce joueur",
"sanctions": "Les sanctions appliquées",
"sanctionsText": "Voici les sanctions plancher que nous appliquons. Si nous constatons des circonstances aggravantes (installation d'un logiciel espion sur le client d'un autre joueur par exemple), nous nous réservons le droit d'ajouter des malédictions ou d'appliquer un bannissement définitif immédiatement.",
"penalty": "Sanction sans récidive",
"penaltyRecurrence": "Sanction si récidive",
"penaltyRecurrence2": "Sanction à la seconde récidive",
"curse": "Malédiction",
"banishment": "Bannissement définitif",
"errorInvalidReason": "Raison invalide",
"errorMoreDetails": "Donnez plus de détails",
"messageReportSent": "Votre signalement a été envoyé !"
}
}
4 changes: 4 additions & 0 deletions config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports.policies = {
'submitSubscription': ['load-user', 'set-locale'],
},

ReportController: {
'*': ['load-user', 'set-locale', 'is-logged-in'],
},

// Blueprint API
'news/*':['load-user', 'is-logged-in', 'is-admin'],
'news/find':[],
Expand Down
3 changes: 3 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@ module.exports.routes = {
'GET /codes': 'CodesController.viewForm',
'GET /codes/use/:code': 'CodesController.useCode',

// Report
'GET /report/:id': 'ReportController.index',
'POST /report/:id': 'ReportController.report',

};
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"moment": "^2.27.0",
"node-fetch": "^2.6.0",
"node-sass": "^4.14.1",
"nodemailer": "^6.4.10",
"nodemailer-smtp-transport": "^2.7.4",
"sails": "^1.2.4",
"sails-hook-grunt": "^4.0.0",
"sails-hook-orm": "^2.1.1",
Expand Down
Loading

0 comments on commit c9c5527

Please sign in to comment.