mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Merge branch 'develop' into api-v3
This commit is contained in:
@@ -40,26 +40,29 @@ describe("Coupons", function() {
|
|||||||
describe("POST /api/v2/coupons/generate/:event", function() {
|
describe("POST /api/v2/coupons/generate/:event", function() {
|
||||||
context("while sudo user", function() {
|
context("while sudo user", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
return makeSudoUser(user, done);
|
makeSudoUser(user, done);
|
||||||
});
|
});
|
||||||
return it("generates coupons", function(done) {
|
|
||||||
|
it("generates coupons", function(done) {
|
||||||
var queries;
|
var queries;
|
||||||
queries = '?count=10';
|
queries = '?count=10';
|
||||||
return request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
|
|
||||||
|
request.post(baseURL + '/coupons/generate/wondercon' + queries).end(function(err, res) {
|
||||||
expectCode(res, 200);
|
expectCode(res, 200);
|
||||||
return Coupon.find({
|
Coupon.find({
|
||||||
event: 'wondercon'
|
event: 'wondercon'
|
||||||
}, function(err, _coupons) {
|
}, function(err, _coupons) {
|
||||||
coupons = _coupons;
|
coupons = _coupons;
|
||||||
expect(coupons.length).to.equal(10);
|
expect(coupons.length).to.equal(10);
|
||||||
_(coupons).each(function(c) {
|
_(coupons).each(function(c) {
|
||||||
return expect(c.event).to.equal('wondercon');
|
expect(c.event).to.equal('wondercon');
|
||||||
}).value();
|
}).value();
|
||||||
return done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return context("while regular user", function() {
|
return context("while regular user", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
return registerNewUser(done, true);
|
return registerNewUser(done, true);
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ api.ensureAdmin = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
api.generateCoupons = function(req,res,next) {
|
api.generateCoupons = function(req,res,next) {
|
||||||
Coupon.generate(req.params.event, req.query.count, function(err){
|
let count = Number(req.query.count);
|
||||||
|
Coupon.generate(req.params.event, count, function(err){
|
||||||
if(err) return next(err);
|
if(err) return next(err);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
//require('winston-mail').Mail;
|
|
||||||
//require('winston-newrelic');
|
|
||||||
|
|
||||||
var logger, loggly;
|
var logger, loggly;
|
||||||
|
|
||||||
@@ -22,51 +20,38 @@ if (nconf.get('LOGGLY:enabled')){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger == null) {
|
if (!logger) {
|
||||||
logger = new (winston.Logger)({});
|
logger = new (winston.Logger)({});
|
||||||
if (nconf.get('NODE_ENV') == 'production') {
|
|
||||||
if (!nconf.get('DISABLE_ERROR_EMAILS') && false) {
|
if (nconf.get('NODE_ENV') !== 'production') {
|
||||||
logger.add(winston.transports.Mail, {
|
logger.add(winston.transports.Console, {colorize:true});
|
||||||
to: nconf.get('ADMIN_EMAIL') || nconf.get('SMTP_USER'),
|
logger.add(winston.transports.File, {filename: 'habitrpg.log'});
|
||||||
from: "HabitRPG <" + nconf.get('SMTP_USER') + ">",
|
}
|
||||||
subject: "HabitRPG Error",
|
|
||||||
host: nconf.get('SMTP_HOST'),
|
|
||||||
port: nconf.get('SMTP_PORT'),
|
|
||||||
tls: nconf.get('SMTP_TLS'),
|
|
||||||
username: nconf.get('SMTP_USER'),
|
|
||||||
password: nconf.get('SMTP_PASS'),
|
|
||||||
level: 'error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.add(winston.transports.Console, {colorize:true});
|
|
||||||
logger.add(winston.transports.File, {filename: 'habitrpg.log'});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A custom log function that wraps Winston. Makes it easy to instrument code
|
// A custom log function that wraps Winston. Makes it easy to instrument code
|
||||||
// and still possible to replace Winston in the future.
|
// and still possible to replace Winston in the future.
|
||||||
module.exports.log = function(/* variable args */) {
|
module.exports.log = function(/* variable args */) {
|
||||||
if (logger)
|
if (logger)
|
||||||
logger.log.apply(logger, arguments);
|
logger.log.apply(logger, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.info = function(/* variable args */) {
|
module.exports.info = function(/* variable args */) {
|
||||||
if (logger)
|
if (logger)
|
||||||
logger.info.apply(logger, arguments);
|
logger.info.apply(logger, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.warn = function(/* variable args */) {
|
module.exports.warn = function(/* variable args */) {
|
||||||
if (logger)
|
if (logger)
|
||||||
logger.warn.apply(logger, arguments);
|
logger.warn.apply(logger, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.error = function(/* variable args */) {
|
module.exports.error = function(/* variable args */) {
|
||||||
if (logger)
|
if (logger)
|
||||||
logger.error.apply(logger, arguments);
|
logger.error.apply(logger, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.loggly = function(/* variable args */){
|
module.exports.loggly = function(/* variable args */){
|
||||||
if (loggly)
|
if (loggly)
|
||||||
loggly.log.apply(loggly, arguments);
|
loggly.log.apply(loggly, arguments);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,15 +8,16 @@ const IS_PROD = nconf.get('IS_PROD');
|
|||||||
const BASE_URL = nconf.get('BASE_URL');
|
const BASE_URL = nconf.get('BASE_URL');
|
||||||
|
|
||||||
module.exports.sendEmail = function(mailData) {
|
module.exports.sendEmail = function(mailData) {
|
||||||
var smtpTransport = nodemailer.createTransport("SMTP",{
|
var smtpTransport = nodemailer.createTransport({
|
||||||
service: nconf.get('SMTP_SERVICE'),
|
service: nconf.get('SMTP_SERVICE'),
|
||||||
auth: {
|
auth: {
|
||||||
user: nconf.get('SMTP_USER'),
|
user: nconf.get('SMTP_USER'),
|
||||||
pass: nconf.get('SMTP_PASS')
|
pass: nconf.get('SMTP_PASS')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
smtpTransport.sendMail(mailData, function(error, response){
|
smtpTransport.sendMail(mailData, function(error, response){
|
||||||
var logging = require('./api-v2/logging');
|
var logging = require('./api-v2/logging');
|
||||||
if(error) logging.error(error);
|
if(error) logging.error(error);
|
||||||
else logging.info("Message sent: " + response.message);
|
else logging.info("Message sent: " + response.message);
|
||||||
smtpTransport.close(); // shut down the connection pool, no more messages
|
smtpTransport.close(); // shut down the connection pool, no more messages
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// Logger utility
|
// Logger utility
|
||||||
// TODO remove winston-mail and winston-newrelic if not used
|
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user