-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from thefirstspine/next
Release 1.11.0
- Loading branch information
Showing
13 changed files
with
374 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
); | ||
}, | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.