mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
feat(emails): add emails on signup, subscription begin and donation
This commit is contained in:
parent
84d1bf9e27
commit
fca45a3c0b
5 changed files with 142 additions and 38 deletions
|
|
@ -20,5 +20,8 @@
|
|||
"GA_ID": "GA_ID",
|
||||
"PAYPAL_USERNAME": "PAYPAL_USERNAME",
|
||||
"PAYPAL_PASSWORD": "PAYPAL_PASSWORD",
|
||||
"PAYPAL_SIGNATURE": "PAYPAL_SIGNATURE"
|
||||
"PAYPAL_SIGNATURE": "PAYPAL_SIGNATURE",
|
||||
"EMAIL_SERVER_URL": "http://example.com",
|
||||
"EMAIL_SERVER_AUTH_USER": "user",
|
||||
"EMAIL_SERVER_AUTH_PASSWORD": "password"
|
||||
}
|
||||
|
|
|
|||
75
package.json
75
package.json
|
|
@ -4,56 +4,57 @@
|
|||
"version": "0.0.0-152",
|
||||
"main": "./src/server.js",
|
||||
"dependencies": {
|
||||
"habitrpg-shared": "git://github.com/HabitRPG/habitrpg-shared#develop",
|
||||
"connect-mongo": "*",
|
||||
"express": "3.5.x",
|
||||
"gzippo": "*",
|
||||
"guid": "*",
|
||||
"moment": "~2.4.0",
|
||||
"stripe": "*",
|
||||
"coffee-script": "1.6.x",
|
||||
"nconf": "*",
|
||||
"icalendar": "git://github.com/lefnire/node-icalendar#master",
|
||||
"resolve": "~0.2.3",
|
||||
"lodash": "~2.2.1",
|
||||
"async": "~0.2.9",
|
||||
"optimist": "~0.5.2",
|
||||
"stylus": "~0.37.0",
|
||||
"bower": "~1.3.8",
|
||||
"coffee-script": "1.6.x",
|
||||
"connect-mongo": "*",
|
||||
"connect-ratelimit": "0.0.6",
|
||||
"coupon-code": "~0.3.0",
|
||||
"domain-middleware": "~0.1.0",
|
||||
"express": "3.5.x",
|
||||
"express-csv": "~0.6.0",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib-uglify": "~0.2.4",
|
||||
"grunt-contrib-stylus": "~0.8.0",
|
||||
"grunt-cli": "~0.1.9",
|
||||
"grunt-concurrent": "~0.3.1",
|
||||
"grunt-contrib-clean": "~0.5.0",
|
||||
"grunt-contrib-cssmin": "~0.6.1",
|
||||
"grunt-contrib-watch": "~0.5.3",
|
||||
"grunt-contrib-copy": "~0.4.1",
|
||||
"grunt-contrib-cssmin": "~0.6.1",
|
||||
"grunt-contrib-stylus": "~0.8.0",
|
||||
"grunt-contrib-uglify": "~0.2.4",
|
||||
"grunt-contrib-watch": "~0.5.3",
|
||||
"grunt-hashres": "~0.3.2",
|
||||
"grunt-nodemon": "~0.1.1",
|
||||
"grunt-concurrent": "~0.3.1",
|
||||
"bower": "~1.3.8",
|
||||
"nib": "~1.0.1",
|
||||
"guid": "*",
|
||||
"gzippo": "*",
|
||||
"habitrpg-shared": "git://github.com/HabitRPG/habitrpg-shared#develop",
|
||||
"icalendar": "git://github.com/lefnire/node-icalendar#master",
|
||||
"jade": "~0.35.0",
|
||||
"validator": "~3.11.2",
|
||||
"nodemailer": "~0.5.2",
|
||||
"grunt-cli": "~0.1.9",
|
||||
"express-csv": "~0.6.0",
|
||||
"pretty-data": "git://github.com/vkiryukhin/pretty-data#master",
|
||||
"js2xmlparser": "~0.1.2",
|
||||
"lodash": "~2.2.1",
|
||||
"moment": "~2.4.0",
|
||||
"mongoose": "3.8.5",
|
||||
"swagger-node-express": "git://github.com/lefnire/swagger-node-express#habitrpg",
|
||||
"mongoose-id-autoinc": "~2013.7.14-4",
|
||||
"nconf": "*",
|
||||
"newrelic": "~1.10.3",
|
||||
"nib": "~1.0.1",
|
||||
"nodemailer": "~0.5.2",
|
||||
"optimist": "~0.5.2",
|
||||
"passport": "~0.1.18",
|
||||
"passport-facebook": "~1.0.2",
|
||||
"newrelic": "~1.10.3",
|
||||
"connect-ratelimit": "0.0.6",
|
||||
"paypal-express-checkout": "git://github.com/HabitRPG/node-paypal-express-checkout#habitrpg",
|
||||
"paypal-ipn": "~1.0.1",
|
||||
"paypal-recurring": "git://github.com/jaybryant/paypal-recurring#656b496f43440893c984700191666a5c5c535dca",
|
||||
"pretty-data": "git://github.com/vkiryukhin/pretty-data#master",
|
||||
"request": "~2.42.0",
|
||||
"resolve": "~0.2.3",
|
||||
"stripe": "*",
|
||||
"stylus": "~0.37.0",
|
||||
"swagger-node-express": "git://github.com/lefnire/swagger-node-express#habitrpg",
|
||||
"universal-analytics": "~0.3.2",
|
||||
"validator": "~3.11.2",
|
||||
"winston": "~0.7.2",
|
||||
"winston-mail": "~0.2.7",
|
||||
"winston-newrelic": "~0.1.4",
|
||||
"domain-middleware": "~0.1.0",
|
||||
"universal-analytics": "~0.3.2",
|
||||
"paypal-express-checkout": "git://github.com/HabitRPG/node-paypal-express-checkout#habitrpg",
|
||||
"paypal-recurring": "git://github.com/jaybryant/paypal-recurring#656b496f43440893c984700191666a5c5c535dca",
|
||||
"paypal-ipn": "~1.0.1",
|
||||
"coupon-code": "~0.3.0",
|
||||
"mongoose-id-autoinc": "~2013.7.14-4"
|
||||
"winston-newrelic": "~0.1.4"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
BIN
public/emails/images/subscription-begins-v1.png
Normal file
BIN
public/emails/images/subscription-begins-v1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
|
|
@ -5,10 +5,13 @@ var shared = require('habitrpg-shared');
|
|||
var async = require('async');
|
||||
var utils = require('../utils');
|
||||
var nconf = require('nconf');
|
||||
var request = require('request');
|
||||
var User = require('../models/user').model;
|
||||
var ga = require('./../utils').ga;
|
||||
var i18n = require('./../i18n');
|
||||
|
||||
var isProd = nconf.get('NODE_ENV') === 'production';
|
||||
|
||||
var api = module.exports;
|
||||
|
||||
var NO_TOKEN_OR_UID = { err: "You must include a token and uid (user id) in your request"};
|
||||
|
|
@ -109,6 +112,26 @@ api.registerUser = function(req, res, next) {
|
|||
}
|
||||
|
||||
user.save(cb);
|
||||
if(isProd){
|
||||
request({
|
||||
url: nconf.get('EMAIL_SERVER_URL') + '/job',
|
||||
method: 'POST',
|
||||
auth: {
|
||||
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
|
||||
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
|
||||
},
|
||||
json: {
|
||||
type: 'email',
|
||||
data: {
|
||||
emailType: 'welcome',
|
||||
to: {
|
||||
name: username,
|
||||
email: email
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
ga.event('register', 'Local').send()
|
||||
}
|
||||
], function(err, saved) {
|
||||
|
|
@ -294,6 +317,26 @@ api.setupPassport = function(router) {
|
|||
}
|
||||
});
|
||||
user.save(cb);
|
||||
if(isProd && req.user.emails && req.user.emails[0] && req.user.emails[0].value){
|
||||
request({
|
||||
url: nconf.get('EMAIL_SERVER_URL') + '/job',
|
||||
method: 'POST',
|
||||
auth: {
|
||||
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
|
||||
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
|
||||
},
|
||||
json: {
|
||||
type: 'email',
|
||||
data: {
|
||||
emailType: 'welcome',
|
||||
to: {
|
||||
name: req.user.displayName || req.user.username,
|
||||
email: req.user.emails[0].value
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
ga.event('register', 'Facebook').send()
|
||||
}
|
||||
], function(err, saved){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ var User = require('./../models/user').model;
|
|||
var ga = require('./../utils').ga;
|
||||
var logging = require('./../logging');
|
||||
var userAPI = require('./user');
|
||||
var request = require('request');
|
||||
var api = module.exports;
|
||||
var isProduction = nconf.get("NODE_ENV") === "production";
|
||||
|
||||
|
|
@ -54,6 +55,34 @@ function createSubscription(user, data) {
|
|||
revealMysteryItems(user);
|
||||
user.purchased.txnCount++;
|
||||
ga.event('subscribe', data.paymentMethod).send()
|
||||
if(isProduction){
|
||||
var email, name;
|
||||
if(user.auth.local){
|
||||
email = user.auth.local.email;
|
||||
name = user.profile.name || user.auth.local.username;
|
||||
}else if(user.auth.facebook && user.auth.facebook.emails && user.auth.facebook.emails[0] && user.auth.facebook.emails[0].value){
|
||||
email = user.auth.facebook.emails[0].value;
|
||||
name = user.auth.facebook.displayName || user.auth.facebook.username;
|
||||
}
|
||||
request({
|
||||
url: nconf.get('EMAIL_SERVER_URL') + '/job',
|
||||
method: 'POST',
|
||||
auth: {
|
||||
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
|
||||
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
|
||||
},
|
||||
json: {
|
||||
type: 'email',
|
||||
data: {
|
||||
emailType: 'subscription-begins',
|
||||
to: {
|
||||
name: req.user.displayName || req.user.username,
|
||||
email: req.user.emails[0].value
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
ga.transaction(data.customerId, 5).item(5, 1, data.paymentMethod.toLowerCase() + '-subscription', data.paymentMethod + " > Stripe").send();
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +103,34 @@ function buyGems(user, data) {
|
|||
user.purchased.txnCount++;
|
||||
ga.event('checkout', data.paymentMethod).send();
|
||||
ga.transaction(data.customerId, 5).item(5, 1, data.paymentMethod.toLowerCase() + "-checkout", "Gems > " + data.paymentMethod).send();
|
||||
if(isProduction){
|
||||
var email, name;
|
||||
if(user.auth.local){
|
||||
email = user.auth.local.email;
|
||||
name = user.profile.name || user.auth.local.username;
|
||||
}else if(user.auth.facebook && user.auth.facebook.emails && user.auth.facebook.emails[0] && user.auth.facebook.emails[0].value){
|
||||
email = user.auth.facebook.emails[0].value;
|
||||
name = user.auth.facebook.displayName || user.auth.facebook.username;
|
||||
}
|
||||
request({
|
||||
url: nconf.get('EMAIL_SERVER_URL') + '/job',
|
||||
method: 'POST',
|
||||
auth: {
|
||||
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
|
||||
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
|
||||
},
|
||||
json: {
|
||||
type: 'email',
|
||||
data: {
|
||||
emailType: 'donation',
|
||||
to: {
|
||||
name: req.user.displayName || req.user.username,
|
||||
email: req.user.emails[0].value
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Expose some functions for tests
|
||||
|
|
|
|||
Loading…
Reference in a new issue