mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-15 16:32:16 +00:00
Merge branch 'develop' of https://github.com/HabitRPG/habitrpg into develop
This commit is contained in:
commit
c7c6181bbc
12 changed files with 112 additions and 20 deletions
7
.bowerrc
7
.bowerrc
|
|
@ -1,3 +1,8 @@
|
|||
{
|
||||
"directory": "public/bower_components"
|
||||
"directory": "public/bower_components",
|
||||
"storage": {
|
||||
"packages": ".bower-cache",
|
||||
"registry": ".bower-registry"
|
||||
},
|
||||
"tmp": ".bower-tmp"
|
||||
}
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ npm-debug.log
|
|||
lib
|
||||
public/bower_components
|
||||
build
|
||||
newrelic_agent.log
|
||||
|
||||
src/*/*.map
|
||||
src/*/*/*.map
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@ Gruntfile.js
|
|||
CHANGELOG.md
|
||||
.idea*
|
||||
.git*
|
||||
newrelic_agent.log
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@
|
|||
"SMTP_SERVICE":"Gmail",
|
||||
"STRIPE_API_KEY":"aaaabbbbccccddddeeeeffff00001111",
|
||||
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
||||
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com"
|
||||
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com",
|
||||
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY"
|
||||
}
|
||||
|
|
|
|||
25
newrelic.js
Normal file
25
newrelic.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* New Relic agent configuration.
|
||||
*
|
||||
* See lib/config.defaults.js in the agent distribution for a more complete
|
||||
* description of configuration variables and their potential values.
|
||||
*/
|
||||
var nconf = require('nconf')
|
||||
exports.config = {
|
||||
/**
|
||||
* Array of application names.
|
||||
*/
|
||||
app_name : ['HabitRPG'],
|
||||
/**
|
||||
* Your New Relic license key.
|
||||
*/
|
||||
license_key : nconf.get('NEW_RELIC_LICENSE_KEY'),
|
||||
logging : {
|
||||
/**
|
||||
* Level at which to log. 'trace' is most useful to New Relic when diagnosing
|
||||
* issues with the agent, 'info' and higher will impose the least overhead on
|
||||
* production applications.
|
||||
*/
|
||||
level : 'warning'
|
||||
}
|
||||
};
|
||||
|
|
@ -43,7 +43,8 @@
|
|||
"domain-middleware": "~0.1.0",
|
||||
"swagger-node-express": "git://github.com/lefnire/swagger-node-express#habitrpg",
|
||||
"passport": "~0.1.18",
|
||||
"passport-facebook": "~1.0.2"
|
||||
"passport-facebook": "~1.0.2",
|
||||
"newrelic": "~1.3.0"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
|
|
@ -166,6 +166,9 @@ acceptablePUTPaths = _.reduce(require('./../models/user').schema.paths, function
|
|||
if (found) m[leaf]=true;
|
||||
return m;
|
||||
}, {})
|
||||
_.each('stats.gp'.split(' '), function(removePath){
|
||||
delete acceptablePUTPaths[removePath];
|
||||
})
|
||||
|
||||
/**
|
||||
* Update user
|
||||
|
|
@ -257,6 +260,8 @@ api.addTenGems = function(req, res) {
|
|||
})
|
||||
}
|
||||
|
||||
// TODO delete plan
|
||||
|
||||
/*
|
||||
Setup Stripe response when posting payment
|
||||
*/
|
||||
|
|
@ -264,20 +269,39 @@ api.buyGems = function(req, res) {
|
|||
var api_key = nconf.get('STRIPE_API_KEY');
|
||||
var stripe = require("stripe")(api_key);
|
||||
var token = req.body.id;
|
||||
// console.dir {token:token, req:req}, 'stripe'
|
||||
var user = res.locals.user;
|
||||
|
||||
async.waterfall([
|
||||
function(cb){
|
||||
stripe.charges.create({
|
||||
amount: "500", // $5
|
||||
currency: "usd",
|
||||
card: token
|
||||
}, cb);
|
||||
if (req.query.plan) {
|
||||
stripe.customers.create({
|
||||
email: req.body.email,
|
||||
metadata: {uuid: res.locals.user._id},
|
||||
card: token,
|
||||
plan: req.query.plan,
|
||||
}, cb);
|
||||
} else {
|
||||
stripe.charges.create({
|
||||
amount: "500", // $5
|
||||
currency: "usd",
|
||||
card: token
|
||||
}, cb);
|
||||
}
|
||||
},
|
||||
function(response, cb) {
|
||||
res.locals.user.balance += 5;
|
||||
res.locals.user.purchased.ads = true;
|
||||
res.locals.user.save(cb);
|
||||
//user.purchased.ads = true;
|
||||
if (req.query.plan) {
|
||||
user.purchased.plan = {
|
||||
planId:'basic_earned',
|
||||
customerId: response.id,
|
||||
dateCreated: new Date,
|
||||
dateUpdated: new Date,
|
||||
gemsBought: 0
|
||||
};
|
||||
} else {
|
||||
user.balance += 5;
|
||||
}
|
||||
user.save(cb);
|
||||
}
|
||||
], function(err, saved){
|
||||
if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors
|
||||
|
|
@ -285,6 +309,29 @@ api.buyGems = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
api.cancelSubscription = function(req, res) {
|
||||
var api_key = nconf.get('STRIPE_API_KEY');
|
||||
var stripe = require("stripe")(api_key);
|
||||
var user = res.locals.user;
|
||||
if (!user.purchased.plan.customerId)
|
||||
return res.json(401, {err: "User does not have a plan subscription"});
|
||||
|
||||
async.waterfall([
|
||||
function(cb) {
|
||||
stripe.customers.del(user.purchased.plan.customerId, cb);
|
||||
},
|
||||
function(response, cb) {
|
||||
user.purchased.plan = {};
|
||||
user.markModified('purchased.plan');
|
||||
user.save(cb);
|
||||
}
|
||||
], function(err, saved){
|
||||
if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors
|
||||
res.send(200, saved);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
api.buyGemsPaypalIPN = function(req, res, next) {
|
||||
res.send(200);
|
||||
ipn.verify(req.body, function callback(err, msg) {
|
||||
|
|
@ -298,7 +345,7 @@ api.buyGemsPaypalIPN = function(req, res, next) {
|
|||
if (_.isEmpty(user)) err = "user not found with uuid " + uuid + " when completing paypal transaction";
|
||||
if (err) return nex(err);
|
||||
user.balance += 5;
|
||||
user.purchased.ads = true;
|
||||
//user.purchased.ads = true;
|
||||
user.save();
|
||||
console.log('PayPal transaction completed and user updated');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -78,6 +78,13 @@ var UserSchema = new Schema({
|
|||
skin: {type: Schema.Types.Mixed, 'default': {}}, // eg, {skeleton: true, pumpkin: true, eb052b: true}
|
||||
hair: {type: Schema.Types.Mixed, 'default': {}},
|
||||
shirt: {type: Schema.Types.Mixed, 'default': {}},
|
||||
plan: {
|
||||
planId: String,
|
||||
customerId: String,
|
||||
dateCreated: Date,
|
||||
dateUpdated: Date,
|
||||
gemsBought: {type: Number, 'default': 0}
|
||||
}
|
||||
},
|
||||
|
||||
flags: {
|
||||
|
|
|
|||
|
|
@ -304,6 +304,11 @@ module.exports = (swagger, v2) ->
|
|||
middleware: auth.auth
|
||||
action:user.buyGems
|
||||
|
||||
"/user/cancel-subscription":
|
||||
spec: method: 'POST', description: "Do not use this route"
|
||||
middleware: auth.auth
|
||||
action:user.cancelSubscription
|
||||
|
||||
"/user/buy-gems/paypal-ipn":
|
||||
spec:
|
||||
method: 'POST'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Only do the minimal amount of work before forking just in case of a dyno restart
|
||||
var nconf = require('nconf');
|
||||
var utils = require('./utils');
|
||||
utils.setupConfig();
|
||||
|
||||
require('coffee-script') // remove this once we've fully converted over
|
||||
var express = require("express");
|
||||
|
|
@ -8,16 +9,12 @@ var path = require("path");
|
|||
var domainMiddleware = require('domain-middleware');
|
||||
var swagger = require("swagger-node-express");
|
||||
|
||||
var utils = require('./utils');
|
||||
var middleware = require('./middleware');
|
||||
|
||||
var TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
|
||||
var app = express();
|
||||
var server;
|
||||
|
||||
// ------------ Setup configurations ------------
|
||||
utils.setupConfig();
|
||||
|
||||
// ------------ MongoDB Configuration ------------
|
||||
mongoose = require('mongoose');
|
||||
require('./models/user'); //load up the user schema - TODO is this necessary?
|
||||
|
|
@ -74,7 +71,8 @@ passport.use(new FacebookStrategy({
|
|||
// ------------ Server Configuration ------------
|
||||
app.set("port", nconf.get('PORT'));
|
||||
|
||||
if (!process.env.SUPPRESS) app.use(express.logger("dev"));
|
||||
if (nconf.get('NODE_ENV') !== 'production')
|
||||
app.use(express.logger("dev"));
|
||||
app.use(express.compress());
|
||||
app.set("views", __dirname + "/../views");
|
||||
app.set("view engine", "jade");
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ module.exports.setupConfig = function(){
|
|||
if (nconf.get('NODE_ENV') === "development") {
|
||||
Error.stackTraceLimit = Infinity;
|
||||
}
|
||||
if (nconf.get('NODE_ENV') === 'production') require('newrelic');
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ div(modal='modals.newStuff')
|
|||
tr
|
||||
td
|
||||
h5 <a href='/#/options/groups/challenges/95533e05-1ff9-4e46-970b-d77219f199e9' target='_blank'>Spread The Word Challenge</a> Update
|
||||
p We have 2k+ submissions, holy cow! Great job everyone! Now, we need to go through these manually, so it will take a few days to a couple weeks to process. The challenge will stay open until we're done choosing our winners, but be sure to edit the To-Do with your submission URL before 1/31, as that's the cut-off date for processing. We'll send a Tweet out when the winner has been selected, so follow <a href='https://twitter.com/habitrpg' target='_blank'>@habitrpg</a> and stay tuned.
|
||||
p We have 1k+ submissions, holy cow! Great job everyone! Now, we need to go through these manually, so it will take a few days to a couple weeks to process. The challenge will stay open until we're done choosing our winners, but be sure to edit the To-Do with your submission URL before 1/31, as that's the cut-off date for processing. We'll send a Tweet out when the winner has been selected, so follow <a href='https://twitter.com/habitrpg' target='_blank'>@habitrpg</a> and stay tuned.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue