Permalink
Browse files

feat: add support for failure notifications

  • Loading branch information...
1 parent 9c54ed3 commit dd0370a3e0a781044f82a57df8d6a47ac73dddb3 @remy remy committed Jul 19, 2016
View
@@ -2,7 +2,7 @@
'use strict';
var memcache = require('memcached');
var repl = require('repl');
-var Promise = require('promise');
+var Promise = require('es6-promise');
var m = new memcache('localhost:11211');
var mysql = require('../lib/db/mysql');
var config = require('../lib/config');
@@ -0,0 +1,96 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="viewport" content="width=device-width, target-densitydpi=device-dpi">
+ </head>
+ <body id="jsbinannouce" style="width: 100% !important; -webkit-text-size-adjust: none; margin: 0; padding: 0;">
+ <center>
+ <table id="backgroundTable" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100% !important; width: 100% !important; color: #4c4c4c; font-size: 15px; line-height: 150%; background: #ffffff; margin: 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td align="center" valign="top" style="vertical-align: top; padding: 0;">
+ <table class="container" id="templateContainer" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 600px; color: #4c4c4c; font-size: 15px; line-height: 150%; background: #ffffff; margin: 0px 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td class="container templateContainerPadding" align="center" valign="top" style="vertical-align: top; padding: 0 40px;">
+ <table id="templateContent" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 100%; background: #ffffff; margin: 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td style="vertical-align: top; text-align: left; padding: 0;" align="left" valign="top">
+
+
+<!-- BODY -->
+<p style="margin: 20px 0;">Just to let you know, the subscription charge for your JS Bin Pro account on {{created}}, failed against the card ending in <span style="font-family: monospace; background: #ddd;">{{last4}}</span>.</p>
+
+<p style="margin: 20px 0;">You'll need to fix this before your subscription automatically cancelled (after 3 charge attempts).</p>
+
+<p style="margin: 20px 0;"><a style="font-weight: bold; text-decoration: underline;" href="https://jsbin.com/account/subscription?utm_medium=email">Update your card details today</a></p>
+
+<p style="margin: 20px 0;">Many thanks,</p>
+<p style="margin: 20px 0;">– <a href="https://twitter.com/rem">Remy</a> (creator of JS Bin)</p>
+
+<!-- /BODY -->
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr style="vertical-align: top; padding: 0;">
+ <td class="container templateContainerPadding" align="center" valign="top" style="vertical-align: top; padding: 0 40px;">
+ <table id="footerContent" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 100%; border-top-style: solid; border-top-color: #ebeaef; color: #999999; font-size: 12px; background: #ffffff; margin: 0; padding: 0; border-width: 1px 0 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td valign="top" style="vertical-align: top; text-align: left; padding: 0;" align="left">
+ <p style="margin: 20px 0;">
+ Your username: {{user.name}}<br>
+ </p>
+ </td>
+ <td width="30">&nbsp;</td>
+ <td valign="top" style="vertical-align: top; text-align: right; padding: 0;" align="right">
+ <p style="margin: 20px 0;">JS Bin Ltd.<br>Company No.&nbsp;8998555<br>Made in Brighton, UK</p>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" style="vertical-align: top; text-align: center; padding: 0;" align="center" colspan="3">
+ <a style="color: #00F;font-weight: bold;text-decoration: none;" href="http://jsbin.com/upgrade?utm_source=pro-announce3&utm_medium=email&utm_content=logo&utm_campaign=pro"><img src="http://static.jsbin.com/images/jsbin-knockout.png" alt="JS Bin" width="128" height="128" style="outline: none; text-decoration: none; border: 0;" /></a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </center>
+
+<style type="text/css">
+body {
+width: 100% !important;
+}
+.ReadMsgBody {
+width: 100%;
+}
+.ExternalClass {
+width: 100%;
+}
+body {
+-webkit-text-size-adjust: none;
+}
+body {
+margin: 0; padding: 0;
+}
+img {
+border: 0; outline: none; text-decoration: none;
+}
+#backgroundTable {
+height: 100% !important; margin: 0; padding: 0; width: 100% !important;
+}
+#backgroundTable {
+color: #4c4c4c; background-color: #ffffff; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; font-size: 15px; line-height: 150%;
+}
+
+@media screen and (max-width: 600px) {
+ body, table, td, p, a, li, blockquote { -webkit-text-size-adjust: none !important }
+ body { width: 100% !important; min-width: 100% !important }
+ .container { width: auto !important; padding: 0 10px !important;}
+}</style>
+</body>
+</html>
@@ -0,0 +1,11 @@
+Just to let you know, the subscription charge for your JS Bin Pro account on {{created}}, failed against the card ending in "{{last4}}".
+
+You'll need to fix this before your subscription automatically cancelled (after 3 charge attempts).
+
+Update your card details today:
+
+https://jsbin.com/account/subscription
+
+Many thanks,
+
+– Remy (creator of JS Bin)
View
@@ -0,0 +1,100 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="viewport" content="width=device-width, target-densitydpi=device-dpi">
+ </head>
+ <body id="jsbinannouce" style="width: 100% !important; -webkit-text-size-adjust: none; margin: 0; padding: 0;">
+ <center>
+ <table id="backgroundTable" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100% !important; width: 100% !important; color: #4c4c4c; font-size: 15px; line-height: 150%; background: #ffffff; margin: 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td align="center" valign="top" style="vertical-align: top; padding: 0;">
+ <table class="container" id="templateContainer" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 600px; color: #4c4c4c; font-size: 15px; line-height: 150%; background: #ffffff; margin: 0px 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td class="container templateContainerPadding" align="center" valign="top" style="vertical-align: top; padding: 0 40px;">
+ <table id="templateContent" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 100%; background: #ffffff; margin: 0; padding: 0; border: 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td style="vertical-align: top; text-align: left; padding: 0;" align="left" valign="top">
+
+
+<!-- BODY -->
+<p style="margin: 20px 0;">Welcome to JS Bin!</p>
+
+<p style="margin: 20px 0;">Thanks for signing up. To get familiar with JS Bin, check out our <a style="text-decoration: underline;" href="https://jsbin.com/help?utm_medium=email">help</a> and follow <a style="text-decoration: underline;" href="https://twitter.com/js_bin">@js_bin</a> on Twitter.</p>
+{{#if code}}
+<p style="margin: 20px 0;">As a special gift, I'm offering you 60 days free Pro – <span style="font-weight: bold">total saving of over&nbsp;$100(!)</span> when you subscribe to a yearly pro account with the special code: <a style="font-weight: bold;text-decoration: underline;" href="https://jsbin.com/upgrade?coupon={{code}}&amp;utm_source=welcome-email&amp;utm_medium=email&amp;utm_campaign=welcome-email-discount
+">{{code}}</a> (valid for a month from today).</p>
+{{else}}
+<p style="margin: 20px 0;">If you want to power-up your JS Bin usage, you can <a href="https://jsbin.com/upgrade?coupon={{code}}&amp;utm_source=welcome-email&amp;utm_medium=email&amp;utm_campaign=welcome-email">upgrade your account to Pro today</a>, and you'll have access to unlimited private bins, asset uploading, experimental features and more.</p>
+{{/if}}
+
+<p style="margin: 20px 0;">Thanks again,</p>
+<p style="margin: 20px 0;">– <a href="https://twitter.com/rem">Remy</a> (creator of JS Bin)</p>
+
+<!-- /BODY -->
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr style="vertical-align: top; padding: 0;">
+ <td class="container templateContainerPadding" align="center" valign="top" style="vertical-align: top; padding: 0 40px;">
+ <table id="footerContent" style="border-spacing: 0; border-collapse: collapse; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; height: 100%; width: 100%; border-top-style: solid; border-top-color: #ebeaef; color: #999999; font-size: 12px; background: #ffffff; margin: 0; padding: 0; border-width: 1px 0 0;">
+ <tr style="vertical-align: top; padding: 0;">
+ <td valign="top" style="vertical-align: top; text-align: left; padding: 0;" align="left">
+ <p style="margin: 20px 0;">
+ Your username: {{user.name}}<br>
+ </p>
+ </td>
+ <td width="30">&nbsp;</td>
+ <td valign="top" style="vertical-align: top; text-align: right; padding: 0;" align="right">
+ <p style="margin: 20px 0;">JS Bin Ltd.<br>Company No.&nbsp;8998555<br>Made in Brighton, UK</p>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" style="vertical-align: top; text-align: center; padding: 0;" align="center" colspan="3">
+ <a style="color: #00F;font-weight: bold;text-decoration: none;" href="https://jsbin.com/upgrade?utm_source=welcome-email&utm_medium=email&utm_campaign=welcome-email"><img src="https://static.jsbin.com/images/jsbin-knockout.png" alt="JS Bin" width="128" height="128" style="outline: none; text-decoration: none; border: 0;" /></a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </center>
+
+<style type="text/css">
+body {
+width: 100% !important;
+}
+.ReadMsgBody {
+width: 100%;
+}
+.ExternalClass {
+width: 100%;
+}
+body {
+-webkit-text-size-adjust: none;
+}
+body {
+margin: 0; padding: 0;
+}
+img {
+border: 0; outline: none; text-decoration: none;
+}
+#backgroundTable {
+height: 100% !important; margin: 0; padding: 0; width: 100% !important;
+}
+#backgroundTable {
+color: #4c4c4c; background-color: #ffffff; font-family: proxima-nova, 'helvetica neue', helvetica, arial, geneva, sans-serif; font-size: 15px; line-height: 150%;
+}
+
+@media screen and (max-width: 600px) {
+ body, table, td, p, a, li, blockquote { -webkit-text-size-adjust: none !important }
+ body { width: 100% !important; min-width: 100% !important }
+ .container { width: auto !important; padding: 0 10px !important;}
+}</style>
+</body>
+</html>
View
@@ -0,0 +1,16 @@
+Welcome to JS Bin!
+
+Thanks for signing up. To get familiar with JS Bin, check out our https://jsbin.com/help and follow us https://twitter.com/js_bin on Twitter.
+
+If you want to power-up your JS Bin usage, you can upgrade your account to Pro today, and you'll have access to unlimited private bins, asset uploading, experimental features and more: https://jsbin.com/upgrade
+
+Thanks again,
+
+– Remy (creator of JS Bin)
+
+---
+
+Your username: {{user.name}}
+
+JS Bin Ltd. Company No. 8998555
+Made in Brighton, UK
@@ -1,7 +1,6 @@
module.exports = function (app, connection) {
'use strict';
var memcached = require('./store')(connection);
- var RSVP = require('rsvp');
var UserModel = require('../../models').user;
var undefsafe = require('undefsafe');
var feature = require('../../features');
@@ -24,7 +23,7 @@ module.exports = function (app, connection) {
var setUserMetadata = setMetadata.bind(null, req);
var setMemcachedData = populateMemcached.bind(null, key);
- var promise = new RSVP.Promise(function (resolve, reject) {
+ var promise = new Promise(function (resolve, reject) {
// go to database get data about user etc...
UserModel.load(username, function (err, user) {
if (err || !user) {
@@ -2,7 +2,6 @@
var net = require('net');
var Memcached = require('memcached');
var replify = require('replify');
-var Promise = require('rsvp').Promise;
var testForMemcachedServer = function (connection) {
return new Promise(function (resolve, reject) {
View
@@ -1,4 +1,6 @@
'use strict';
+global.Promise = require('promise'); // expose
+
var nodemailer = require('nodemailer'),
express = require('express'),
flatten = require('flatten.js').flatten,
View
@@ -0,0 +1,11 @@
+module.exports = {
+ sendMail: function (email, callback) {
+ if (email.quiet) {
+ return callback(null, email);
+ }
+ console.log('--------- DUMMY EMAIL ---------');
+ console.log(email);
+ console.log('-------------------------------');
+ callback(null, email);
+ }
+};
@@ -0,0 +1,65 @@
+var EmailService = function EmailService(transporter, settings) {
+ this.transporter = transporter;
+ this.settings = settings;
+};
+
+EmailService.prototype.createEmail = function (to, opts) {
+ var text, subject;
+ if (opts) {
+ if (typeof opts === 'string') {
+ text = opts;
+ subject = this.settings.subject;
+ } else {
+ text = opts.body || opts.text || '';
+ subject = opts.subject || this.settings.subject;
+ }
+ } else {
+ opts = to;
+ to = opts.to;
+ subject = opts.subject || this.settings.subject;
+ text = opts.body || opts.text || '';
+ }
+ var emailData = {
+ from: opts.from || this.settings.from,
+ to: to,
+ subject: subject,
+ text: text
+ };
+ var email = new Email(this, emailData);
+ return email;
+};
+
+EmailService.prototype.sendEmail = function (email) {
+ var self = this;
+ if (email instanceof Email) {
+ email = email.data;
+ }
+ var promise = new Promise(function (resolve, reject) {
+ self.transporter.sendMail(email, function (err, info) {
+ if (err) {
+ return reject(err);
+ }
+ resolve(info);
+ });
+ });
+ return promise;
+};
+
+var Email = function Email(Service, data) {
+ this.Service = Service;
+ this.data = data;
+ Object.defineProperty(this, 'body', {
+ set: function (newValue) {
+ this.data.text = newValue;
+ }
+ });
+};
+
+Email.prototype.send = function (to) {
+ if (typeof to === 'string') {
+ this.data.to = to;
+ }
+ return this.Service.sendEmail(this.data);
+};
+
+module.exports = EmailService;
Oops, something went wrong.

0 comments on commit dd0370a

Please sign in to comment.