From 717e87b7422db8e1eda655fbf04e45fe5f877c9b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 20 Jan 2015 00:10:23 -0500 Subject: combining webhook stuff --- server/lib/schemas/User.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'server/lib/schemas/User.js') diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index 180a140..ae1d912 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -54,7 +54,9 @@ var UserSchema = new mongoose.Schema({ type: String, default: "", }, - + + plan_level: { type: Number, default: 0 }, + location: { type: String, default: "" }, photo: { type: String, default: "" }, bio: { type: String, default: "" }, -- cgit v1.2.3-70-g09d2 From 3eee6a15ee44a75f6deedd073f60b88d342d56ef Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 22 Jan 2015 16:54:08 -0500 Subject: recurly links on brochure --- server/lib/schemas/Plan.js | 2 ++ server/lib/schemas/User.js | 1 + server/lib/webhook/index.js | 1 + views/about/brochure.ejs | 19 +++++++++++++++---- 4 files changed, 19 insertions(+), 4 deletions(-) (limited to 'server/lib/schemas/User.js') diff --git a/server/lib/schemas/Plan.js b/server/lib/schemas/Plan.js index 1208672..8a19b99 100644 --- a/server/lib/schemas/Plan.js +++ b/server/lib/schemas/Plan.js @@ -10,6 +10,8 @@ var PlanSchema = new mongoose.Schema({ name: { type: String }, slug: { type: String }, + level: { type: Number }, + monthly_price: { type: Number }, yearly_price: { type: Number }, diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index ae1d912..867939e 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -56,6 +56,7 @@ var UserSchema = new mongoose.Schema({ }, plan_level: { type: Number, default: 0 }, + subscription_id: { type: mongoose.Schema.ObjectId }, location: { type: String, default: "" }, photo: { type: String, default: "" }, diff --git a/server/lib/webhook/index.js b/server/lib/webhook/index.js index c4b4b76..ebbd01a 100644 --- a/server/lib/webhook/index.js +++ b/server/lib/webhook/index.js @@ -33,6 +33,7 @@ var subscription = module.exports = { callbacks: { // accounts new_account_notification: function(data){ + // }, canceled_account_notification: function(data){ }, diff --git a/views/about/brochure.ejs b/views/about/brochure.ejs index e75f8c6..cffa51f 100644 --- a/views/about/brochure.ejs +++ b/views/about/brochure.ejs @@ -33,8 +33,14 @@
  • Each new floor plan can have up to [[- plans.basic.basic_project_limit ]] exhibitions
  • VValls logo appears when embedding an exhibition on a web page
  • - - + [[ if (! logged_in) { ]] + + [[ } else if (! profile.plan_level || profile.plan_level < plan.level) { ]] + + [[ } else if (profile.plan_level == plan.level) { ]] + Current Level + [[ } else { ]] + [[ } ]] @@ -49,8 +55,13 @@
  • Includes planning for 3D objects in the room
  • No VValls logo on embed
  • - - + [[ if (! logged_in) { ]] + + [[ } else if (! profile.plan_level || profile.plan_level < plan.level) { ]] + + [[ } else if (profile.plan_level == plan.level) { ]] + Current Level + [[ } ]] -- cgit v1.2.3-70-g09d2 From e0debd761bc24cd42f4140d2b6cc32a4271fe975 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Fri, 23 Jan 2015 02:35:46 -0500 Subject: getting webhooks in order.. didnt need as many as i thought --- Procfile | 3 +- config.json.example | 1 + server/index.js | 2 +- server/lib/schemas/User.js | 2 + server/lib/webhook/config.js | 2 +- server/lib/webhook/index.js | 119 +++++++++++++----------------------------- server/lib/webhook/webhook.js | 118 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 161 insertions(+), 86 deletions(-) create mode 100644 server/lib/webhook/webhook.js (limited to 'server/lib/schemas/User.js') diff --git a/Procfile b/Procfile index 983db91..bab08fb 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ -web: node server \ No newline at end of file +web: node server +webhook: node server/lib/webhook \ No newline at end of file diff --git a/config.json.example b/config.json.example index 6028021..b8c310c 100644 --- a/config.json.example +++ b/config.json.example @@ -3,6 +3,7 @@ "hostName": "lvh.me", "port": 3000, "socketPort": 1337, + "webhookPort": 5000, "databaseHost": "lvh.me", "pageSize": 10, "env": { "development": 1 } diff --git a/server/index.js b/server/index.js index 9a9323c..02fea3c 100644 --- a/server/index.js +++ b/server/index.js @@ -72,7 +72,7 @@ site.setup = function(){ server = http.createServer(app) server.listen(app.get('port'), function () { - console.log('Express server listening on port ' + app.get('port')); + console.log('Vvalls server listening on port ' + app.get('port')); }); // var io = websocket.listen(server) diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index 867939e..77de2d4 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -56,6 +56,8 @@ var UserSchema = new mongoose.Schema({ }, plan_level: { type: Number, default: 0 }, + plan_type: { type: String, default: "free" }, + last_charged: { type: Date, default: null }, subscription_id: { type: mongoose.Schema.ObjectId }, location: { type: String, default: "" }, diff --git a/server/lib/webhook/config.js b/server/lib/webhook/config.js index ecafeb3..3d7e1c5 100644 --- a/server/lib/webhook/config.js +++ b/server/lib/webhook/config.js @@ -1,5 +1,5 @@ module.exports = { - API_KEY: require('process').env['VVALLS_RECURLY_SECRET'], + API_KEY: process.env['VVALLS_RECURLY_SECRET'], SUBDOMAIN: 'vvalls', ENVIRONMENT: 'sandbox', DEBUG: true, diff --git a/server/lib/webhook/index.js b/server/lib/webhook/index.js index ebbd01a..7dd68e6 100644 --- a/server/lib/webhook/index.js +++ b/server/lib/webhook/index.js @@ -1,89 +1,42 @@ -// // where should this live? -// app.get('/subscribe/webhook', views.subscription.webhook); +var config = require('../../../config.json'), + http = require('http'), + express = require('express'), + bodyParser = require('body-parser'), + mongoose = require('mongoose'); -/* jshint node: true */ +var http = require('http'), + express = require('express'), + bodyParser = require('body-parser'), + multer = require('multer'), + MongoStore = require('connect-mongo')(express), + passport = require('passport'), + path = require('path'), + mongoose = require('mongoose'); -var User = require('../schemas/User'), - Subscription = require('../schemas/Subscription'), - config = require('../../../config'), - middleware = require('../middleware'), - util = require('../util'), - _ = require('lodash'), - moment = require('moment'), - xml2js = require('xml2js'), - Recurly = require('node-recurly'), - recurly = new Recurly(require('./config')); +var app = express() +var server +var DATABASE_URI = process.env.MONGOLAB_URI || ('mongodb://' + config.databaseHost + '/vvalls') -var parser = new xml2js.Parser(); -// fs.readFile('./foo.xml', function(err, data) { -// parser.parseString(data, function (err, result) { -// console.log(inspect(result, { colors: true, depth: Infinity })); -// }); -// }); +var site = {} -/* -app.use(express.basicAuth(function(user, pass, callback) { - var result = (user === 'testUser' && pass === 'testPass'); - callback(null, result); -})); -*/ +site.init = function(){ + mongoose.connect(DATABASE_URI, {}, site.ready); +} + +site.ready = function(){ + app.set('port', config.webhookPort); + app.use(bodyParser()); + app.use(express.query()); + app.set('env', config.env.production ? "production" : "development") + app.get('env') === 'development' && app.use(express.errorHandler()); -var subscription = module.exports = { - - callbacks: { - // accounts - new_account_notification: function(data){ - // - }, - canceled_account_notification: function(data){ - }, - billing_info_updated_notification: function(data){ - }, - reactivated_account_notification: function(data){ - }, - - // invoices - new_invoice_notification: function(data){ - }, - closed_invoice_notification: function(data){ - }, - past_due_invoice_notification: function(data){ - }, - - // subscriptions - new_subscription_notification: function(data){ - }, - updated_subscription_notification: function(data){ - }, - canceled_subscription_notification: function(data){ - }, - expired_subscription_notification: function(data){ - }, - renewed_subscription_notification: function(data){ - }, - - // payments - successful_payment_notification: function(data){ - }, - failed_payment_notification: function(data){ - }, - successful_refund_notification: function(data){ - }, - void_payment_notification: function(data){ - }, - }, - - // need a route for the webhook, - // then calls to get appropriate info from the recurly api - webhook: function(req, res){ - res.status(200).end() - parser.parseString(data, function (err, result) { - console.log(inspect(result, { colors: true, depth: Infinity })); - for (var i in data) { - if (subscription.callbacks[i]) { - subscription.callbacks[i](data[i]) - } - } - }); - }, + server = http.createServer(app) + server.listen(app.get('port'), function () { + console.log('Webhook server listening on port ' + app.get('port')); + }); + + app.get('/', function(req,res){ res.send('HI THERE') }) + app.get('/subscribe/webhook', require('./webhook').webhook); } + +site.init() diff --git a/server/lib/webhook/webhook.js b/server/lib/webhook/webhook.js new file mode 100644 index 0000000..067af30 --- /dev/null +++ b/server/lib/webhook/webhook.js @@ -0,0 +1,118 @@ +// // where should this live? +// app.get('/subscribe/webhook', views.subscription.webhook); + +/* +app.use(express.basicAuth(function(user, pass, callback) { + var result = (user === 'testUser' && pass === 'testPass'); + callback(null, result); +})); +*/ + + +/* jshint node: true */ + +var User = require('../schemas/User'), + Subscription = require('../schemas/Subscription'), + config = require('../../../config'), + middleware = require('../middleware'), + util = require('../util'), + _ = require('lodash'), + moment = require('moment'), + xml2js = require('xml2js'), + Recurly = require('node-recurly'), + recurly = new Recurly(require('./config')); + +var parser = new xml2js.Parser(); + +var subscription = module.exports = { + plan_level: { + free: 0, + basic: 1, + pro: 2, + }, + + callbacks: { + // accounts + new_account_notification: function(data){ + // fires on successful signup + // use the account_code to find the user, + }, + canceled_account_notification: function(data){ + }, + billing_info_updated_notification: function(data){ + }, + reactivated_account_notification: function(data){ + }, + + // invoices + new_invoice_notification: function(data){ + }, + closed_invoice_notification: function(data){ + }, + past_due_invoice_notification: function(data){ + }, + + // subscriptions + new_subscription_notification: function(data){ + var account = data.account + User.findOne({ _id: account.account_code }, function(err, user){ + if (err) return; + var subscription = data.subscription + + var plan = subscription.plan.plan_code.split("_") + var plan_type = plan[0] + var plan_period = plan[1] + + user.plan_type = plan_type + user.plan_level = subscription.plan_level[plan_type] + + // subscription.uuid + // subscription.subscription_add_ons[] + // subscription.subscription_add_ons[0].quantity + user.save(function(){ + }) + + }) + }, + updated_subscription_notification: function(data){ + }, + canceled_subscription_notification: function(data){ + }, + expired_subscription_notification: function(data){ + }, + renewed_subscription_notification: function(data){ + }, + + // payments + successful_payment_notification: function(data){ + var account = data.account + User.findOne({ _id: account.account_code }, function(err, user){ + if (err) return; + user.last_charged = new Date(data.transaction.date) + user.save(function(){ + }) + }) + }, + failed_payment_notification: function(data){ + }, + successful_refund_notification: function(data){ + }, + void_payment_notification: function(data){ + }, + + }, + + // need a route for the webhook, + // then calls to get appropriate info from the recurly api + webhook: function(req, res){ + res.status(200).end() + parser.parseString(data, function (err, result) { + console.log(inspect(result, { colors: true, depth: Infinity })); + for (var i in data) { + if (subscription.callbacks[i]) { + subscription.callbacks[i](data[i]) + } + } + }); + }, +} -- cgit v1.2.3-70-g09d2 From 74fb7a313b4d9ad3517e97133febff9cada96fe0 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 23 Jan 2015 14:46:44 -0500 Subject: handle subscribe and payment events with webhook --- server/lib/schemas/Subscription.js | 17 +++--- server/lib/schemas/User.js | 1 - server/lib/webhook/index.js | 4 +- server/lib/webhook/webhook.js | 108 ++++++++++++++++++++++--------------- 4 files changed, 76 insertions(+), 54 deletions(-) (limited to 'server/lib/schemas/User.js') diff --git a/server/lib/schemas/Subscription.js b/server/lib/schemas/Subscription.js index 7f2579b..99e4ebf 100644 --- a/server/lib/schemas/Subscription.js +++ b/server/lib/schemas/Subscription.js @@ -8,14 +8,15 @@ var mongoose = require('mongoose'), var SubscriptionSchema = new mongoose.Schema({ user_id: { type: mongoose.Schema.ObjectId, index: true }, - - monthly_total: { type: Number }, - yearly_total: { type: Number }, - - plans: [{ - tier: { type: String }, - monthly: { type: Boolean }, - projects: [{ type: mongoose.Schema.ObjectId }], + + plan_level: { type: Number, default: 0 }, + plan_type: { type: String, default: "free" }, + last_charged: { type: Date, default: null }, + + subscription_uuid: { type: String }, + subscription_add_ons: [{ + name: { type: String }, + quantity: { type: Number }, }], created_at: { type: Date, default: Date.now }, diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index 77de2d4..06ad33d 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -58,7 +58,6 @@ var UserSchema = new mongoose.Schema({ plan_level: { type: Number, default: 0 }, plan_type: { type: String, default: "free" }, last_charged: { type: Date, default: null }, - subscription_id: { type: mongoose.Schema.ObjectId }, location: { type: String, default: "" }, photo: { type: String, default: "" }, diff --git a/server/lib/webhook/index.js b/server/lib/webhook/index.js index 7dd68e6..11419c2 100644 --- a/server/lib/webhook/index.js +++ b/server/lib/webhook/index.js @@ -13,6 +13,8 @@ var http = require('http'), path = require('path'), mongoose = require('mongoose'); +var webhook = require('./webhook'); + var app = express() var server var DATABASE_URI = process.env.MONGOLAB_URI || ('mongodb://' + config.databaseHost + '/vvalls') @@ -36,7 +38,7 @@ site.ready = function(){ }); app.get('/', function(req,res){ res.send('HI THERE') }) - app.get('/subscribe/webhook', require('./webhook').webhook); + webhook.route(app) } site.init() diff --git a/server/lib/webhook/webhook.js b/server/lib/webhook/webhook.js index 067af30..2e5e627 100644 --- a/server/lib/webhook/webhook.js +++ b/server/lib/webhook/webhook.js @@ -24,7 +24,7 @@ var User = require('../schemas/User'), var parser = new xml2js.Parser(); -var subscription = module.exports = { +var subscribe = module.exports = { plan_level: { free: 0, basic: 1, @@ -32,87 +32,107 @@ var subscription = module.exports = { }, callbacks: { +/* // accounts - new_account_notification: function(data){ + new_account_notification: function(data, user){ // fires on successful signup - // use the account_code to find the user, }, - canceled_account_notification: function(data){ + canceled_account_notification: function(data, user){ }, - billing_info_updated_notification: function(data){ + billing_info_updated_notification: function(data, user){ }, - reactivated_account_notification: function(data){ + reactivated_account_notification: function(data, user){ }, // invoices - new_invoice_notification: function(data){ + new_invoice_notification: function(data, user){ }, - closed_invoice_notification: function(data){ + closed_invoice_notification: function(data, user){ }, - past_due_invoice_notification: function(data){ + past_due_invoice_notification: function(data, user){ }, - +*/ + // subscriptions - new_subscription_notification: function(data){ + new_subscription_notification: function(data, user){ var account = data.account - User.findOne({ _id: account.account_code }, function(err, user){ - if (err) return; - var subscription = data.subscription - - var plan = subscription.plan.plan_code.split("_") + Subscription.findOne({ "uuid": data.subscription.uuid }, function(err, subscription){ + if (err || subscription) return; + + var plan = data.subscription.plan.plan_code.split("-") var plan_type = plan[0] var plan_period = plan[1] user.plan_type = plan_type - user.plan_level = subscription.plan_level[plan_type] - - // subscription.uuid - // subscription.subscription_add_ons[] - // subscription.subscription_add_ons[0].quantity - user.save(function(){ - }) + user.plan_period = plan_period + user.plan_level = subscribe.plan_level[plan_type] + var subscriber = new Subscription () + subscriber.user_id = user._id + subscriber.uuid = data.subscription.uuid + subscriber.add_ons = subscription.add_ons.map(function(add_on){ + return { + name: add_on.plan, + quantity: add_on.quantity, + } + }) + subscriber.save(function(err, data){ + if (err) return; + user.save(function(err){ + // saved! + }) + }) }) }, - updated_subscription_notification: function(data){ + +/* + updated_subscription_notification: function(data, user){ }, - canceled_subscription_notification: function(data){ + canceled_subscription_notification: function(data, user){ }, - expired_subscription_notification: function(data){ + expired_subscription_notification: function(data, user){ }, - renewed_subscription_notification: function(data){ + renewed_subscription_notification: function(data, user){ }, - +*/ // payments - successful_payment_notification: function(data){ + successful_payment_notification: function(data, user){ var account = data.account - User.findOne({ _id: account.account_code }, function(err, user){ - if (err) return; - user.last_charged = new Date(data.transaction.date) - user.save(function(){ - }) - }) + user.last_charged = new Date(data.transaction.date) + user.save(function(){ + }) }, - failed_payment_notification: function(data){ +/* + failed_payment_notification: function(data, user){ }, - successful_refund_notification: function(data){ + successful_refund_notification: function(data, user){ }, - void_payment_notification: function(data){ + void_payment_notification: function(data, user){ }, - +*/ }, - // need a route for the webhook, + execute: function(action, data){ + User.findOne({ _id: data.account.account_code }, function(err, user){ + if (err) { return } + subscribe.callbacks[action](data, user) + }) + }, + // then calls to get appropriate info from the recurly api - webhook: function(req, res){ + handle: function(req, res){ res.status(200).end() parser.parseString(data, function (err, result) { console.log(inspect(result, { colors: true, depth: Infinity })); - for (var i in data) { - if (subscription.callbacks[i]) { - subscription.callbacks[i](data[i]) + for (var action in result) { + if (subscribe.callbacks[action]) { + subscribe.execute(action, result[action]); } } }); }, + + route: function(app){ + app.post('/subscribe/webhook', subscribe.handle); + }, } -- cgit v1.2.3-70-g09d2 From 79fee7f24d43873fc35295eab1d2a089d373e133 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 28 Jan 2015 11:49:08 -0500 Subject: merge --- server/lib/schemas/Subscription.js | 6 +++++ server/lib/schemas/User.js | 1 + server/lib/views/subscription.js | 50 -------------------------------------- 3 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 server/lib/views/subscription.js (limited to 'server/lib/schemas/User.js') diff --git a/server/lib/schemas/Subscription.js b/server/lib/schemas/Subscription.js index 8315009..8ec557d 100644 --- a/server/lib/schemas/Subscription.js +++ b/server/lib/schemas/Subscription.js @@ -17,6 +17,12 @@ var SubscriptionSchema = new mongoose.Schema({ monthly: { type: Boolean }, }], + history: [{ + action: { type: String }, + plan_id: { type: String }, + created_at: { type: Date, default: Date.now }, + }], + created_at: { type: Date, default: Date.now }, updated_at: { type: Date, default: Date.now }, }) diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index 180a140..19b5ede 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -62,6 +62,7 @@ var UserSchema = new mongoose.Schema({ twitterName: { type: String, default: "" }, facebookUrl: { type: String, default: "" }, isStaff: { type: Boolean, default: false }, + subscription_id: { type: mongoose.Schema.ObjectId }, created_at: { type: Date }, updated_at: { type: Date }, last_seen: { type: Date }, diff --git a/server/lib/views/subscription.js b/server/lib/views/subscription.js deleted file mode 100644 index ba54bb4..0000000 --- a/server/lib/views/subscription.js +++ /dev/null @@ -1,50 +0,0 @@ -/* jshint node: true */ - -var User = require('../schemas/User'), - Subscription = require('../schemas/Subscription'), - config = require('../../../config'), - middleware = require('../middleware'), - util = require('../util'), - _ = require('lodash'), - moment = require('moment'); - -var subscription = module.exports = { - - fields: { - user: "_id username displayName photo created_at updated_at last_seen created_ip last_ip", - }, - - defaults: { - user: { - _id: "", username: "", displayName: "", - created_at: "", updated_at: "", created_ip: "", last_ip: "", - }, - }, - - middleware: { - }, - - helpers: { - project: function(project){ - project = project.toObject() - project.date = moment( project.updated_at || project.created_at ).format("M/DD/YYYY hh:mm a") - project.user = {} - return project - }, - }, - - route: function(app){ - app.get('/staff', - middleware.ensureAuthenticated, - middleware.ensureIsStaff, - - staff.middleware.ensureRecentUsers, - staff.middleware.ensureUsersCount, - staff.middleware.ensureProjectsCount, - staff.middleware.ensureMediaCount, - - staff.index - ); - }, - -} -- cgit v1.2.3-70-g09d2 From dd4f0178c7bcb5d14e1308e3877c5ab02eddf000 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 12 Aug 2015 12:37:49 -0400 Subject: modify webhook to support custom plans --- .../javascripts/ui/site/EditSubscriptionModal.js | 1 + server/lib/api/subscription.js | 1 + server/lib/schemas/Subscription.js | 1 + server/lib/schemas/User.js | 1 + server/lib/views/staff/middleware.js | 2 +- server/lib/webhook/webhook.js | 24 ++++++++++++++++------ views/staff/subscriptions/index.ejs | 3 +++ 7 files changed, 26 insertions(+), 7 deletions(-) (limited to 'server/lib/schemas/User.js') diff --git a/public/assets/javascripts/ui/site/EditSubscriptionModal.js b/public/assets/javascripts/ui/site/EditSubscriptionModal.js index 3a20234..1033114 100644 --- a/public/assets/javascripts/ui/site/EditSubscriptionModal.js +++ b/public/assets/javascripts/ui/site/EditSubscriptionModal.js @@ -96,6 +96,7 @@ var EditSubscriptionModal = ModalView.extend({ free: 0, basic: 1, pro: 2, + custom: 3, }, loaded: false, diff --git a/server/lib/api/subscription.js b/server/lib/api/subscription.js index 9c2d6ef..c2fff4c 100644 --- a/server/lib/api/subscription.js +++ b/server/lib/api/subscription.js @@ -16,6 +16,7 @@ var plan_levels = { free: 0, basic: 1, pro: 2, + custom: 3, } var subscription = module.exports = { diff --git a/server/lib/schemas/Subscription.js b/server/lib/schemas/Subscription.js index 355bbe2..bf43e8b 100644 --- a/server/lib/schemas/Subscription.js +++ b/server/lib/schemas/Subscription.js @@ -9,6 +9,7 @@ var mongoose = require('mongoose'), var SubscriptionSchema = new mongoose.Schema({ user_id: { type: mongoose.Schema.ObjectId, index: true }, + plan_code: { type: String, default: "" }, plan_type: { type: String, default: "free" }, plan_period: { type: String, default: "monthly" }, diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index 4b6ff39..e6e7f03 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -55,6 +55,7 @@ var UserSchema = new mongoose.Schema({ default: "", }, + plan_code: { type: String, default: "" }, plan_level: { type: Number, default: 0 }, plan_type: { type: String, default: "free" }, last_charged: { type: Date, default: null }, diff --git a/server/lib/views/staff/middleware.js b/server/lib/views/staff/middleware.js index 5c74d0b..1ea98e9 100644 --- a/server/lib/views/staff/middleware.js +++ b/server/lib/views/staff/middleware.js @@ -40,7 +40,7 @@ var middleware = module.exports = { } if (initial) { if (initial == "?") { - criteria.username = new RegExp('^[$a-zA-Z]', "i") + criteria.username = new RegExp('^[^a-zA-Z]', "i") } else { criteria.username = new RegExp('^' + initial, "i") diff --git a/server/lib/webhook/webhook.js b/server/lib/webhook/webhook.js index 58a13ca..bd51dac 100644 --- a/server/lib/webhook/webhook.js +++ b/server/lib/webhook/webhook.js @@ -26,10 +26,11 @@ var xml_bodyparser = require('express-xml-bodyparser'); var parser = new xml2js.Parser(); var subscribe = module.exports = { - plan_level: { + plan_levels: { free: 0, basic: 1, pro: 2, + custom: 3, }, callbacks: { @@ -62,19 +63,30 @@ var subscribe = module.exports = { Subscription.findOne({ "uuid": uuid }, function(err, old_subscriber){ // if (err) return; - var plan = subscrip.plan[0].plan_code[0].split("-") - var plan_type = plan[0] - var plan_period = plan[1] + var plan, plan_type, plan_code + var plan_code = subscrip.plan[0].plan_code[0] + if (plan_code.indexOf("-") !== -1) { + plan = plan_code.split("-") + plan_type = plan[0] + plan_period = plan[1] + } + else { + plan_type = "custom" + plan_period = "monthly" + } + + user.plan_code = plan_code user.plan_type = plan_type - user.plan_level = subscribe.plan_level[plan_type] + user.plan_level = subscribe.plan_levels[plan_type] var subscriber = old_subscriber || new Subscription () subscriber.uuid = uuid subscriber.user_id = user._id + subscriber.plan_code = plan_code subscriber.plan_type = plan_type subscriber.plan_period = plan_period - subscriber.plan_level = subscribe.plan_level[plan_type] + subscriber.plan_level = subscribe.plan_levels[plan_type] subscriber.add_ons = [] var add_ons = subscrip.subscription_add_ons[0].subscription_add_on if (add_ons) { diff --git a/views/staff/subscriptions/index.ejs b/views/staff/subscriptions/index.ejs index 3efffb5..adf148c 100644 --- a/views/staff/subscriptions/index.ejs +++ b/views/staff/subscriptions/index.ejs @@ -26,6 +26,9 @@ [[- subscription.user.last_seen ]] + + [[- subscription.plan_code ]] + [[ }) ]] -- cgit v1.2.3-70-g09d2 From cc3d0bf036dc934494bf517ebae88bd8544b9b06 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 12 Aug 2015 13:27:07 -0400 Subject: add artist privilege --- .../javascripts/ui/site/EditSubscriptionModal.js | 1 + public/assets/javascripts/ui/site/StaffView.js | 23 +++++++++++++++++++++- server/lib/schemas/User.js | 1 + server/lib/views/staff/index.js | 16 ++++++++++++++- server/lib/webhook/webhook.js | 1 + views/staff/users/show.ejs | 11 ++++++++++- 6 files changed, 50 insertions(+), 3 deletions(-) (limited to 'server/lib/schemas/User.js') diff --git a/public/assets/javascripts/ui/site/EditSubscriptionModal.js b/public/assets/javascripts/ui/site/EditSubscriptionModal.js index 1033114..c1dc9f8 100644 --- a/public/assets/javascripts/ui/site/EditSubscriptionModal.js +++ b/public/assets/javascripts/ui/site/EditSubscriptionModal.js @@ -97,6 +97,7 @@ var EditSubscriptionModal = ModalView.extend({ basic: 1, pro: 2, custom: 3, + artist: 4, }, loaded: false, diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index 59649e3..97f86c2 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -5,12 +5,14 @@ var StaffView = View.extend({ "click #toggle-staff": "toggleStaff", "click #toggle-featured": "toggleFeatured", "click #toggle-stock": "toggleStock", + "click #toggle-artist": "toggleArtist", }, initialize: function() { this.$toggleStaff = $("#toggle-staff") this.$toggleFeatured = $("#toggle-featured") this.$toggleStock = $("#toggle-stock") + this.$toggleArtist = $("#toggle-artist") this.$mediaEmbed = $("#media-embed") if (this.$toggleStaff.length && this.$toggleStaff.data().isstaff) { this.$toggleStaff.html("Is Staff") @@ -21,6 +23,9 @@ var StaffView = View.extend({ if (this.$toggleStock.length && this.$toggleStock.data().stock) { this.$toggleStock.html("Layout is Stock") } + if (this.$toggleArtist.length && this.$toggleArtist.data().isartist) { + this.$toggleArtist.html("Is Artist") + } if (this.$mediaEmbed.length) { var media = this.$mediaEmbed.data() this.$mediaEmbed.html( Parser.tag( media ) ) @@ -75,7 +80,6 @@ var StaffView = View.extend({ }, toggleStock: function(){ - console.log("stock") var state = ! this.$toggleStock.data().stock $.ajax({ type: "put", @@ -93,4 +97,21 @@ var StaffView = View.extend({ }) }, + toggleArtist: function(){ + var state = ! this.$toggleArtist.data().isartist + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/artist", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleArtist.data("stock", data.state) + this.$toggleArtist.html(data.state ? "Is Artist" : "Make Artist") + $("#isArtist").html(data.state ? "yes" : "no") + }.bind(this) + }) + }, }) diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js index e6e7f03..829b360 100644 --- a/server/lib/schemas/User.js +++ b/server/lib/schemas/User.js @@ -67,6 +67,7 @@ var UserSchema = new mongoose.Schema({ twitterName: { type: String, default: "" }, facebookUrl: { type: String, default: "" }, isStaff: { type: Boolean, default: false }, + isArtist: { type: Boolean, default: false }, subscription_id: { type: mongoose.Schema.ObjectId }, created_at: { type: Date }, updated_at: { type: Date }, diff --git a/server/lib/views/staff/index.js b/server/lib/views/staff/index.js index 6a56238..033fc88 100644 --- a/server/lib/views/staff/index.js +++ b/server/lib/views/staff/index.js @@ -75,7 +75,15 @@ var staff = module.exports = { staff.users.bless ); - + app.put('/staff/users/:username/artist', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureProfile, + + staff.users.make_artist + ); + if (app.get('env') === 'development') { app.get('/staff/authorize', middleware.ensureAuthenticated, @@ -304,6 +312,12 @@ var staff = module.exports = { res.json({ state: user.isStaff }) }) }, + make_artist: function(req, res){ + res.locals.profile.isArtist = req.body.state == "true" + res.locals.profile.save(function(err, user){ + res.json({ state: user.isArtist }) + }) + }, }, // /staff/projects/ diff --git a/server/lib/webhook/webhook.js b/server/lib/webhook/webhook.js index bd51dac..896d836 100644 --- a/server/lib/webhook/webhook.js +++ b/server/lib/webhook/webhook.js @@ -31,6 +31,7 @@ var subscribe = module.exports = { basic: 1, pro: 2, custom: 3, + artist: 4, }, callbacks: { diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index e441109..a434b57 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -35,7 +35,7 @@ plan - [[- profile.plan_type ]] + [[- profile.plan_code ]] @@ -101,12 +101,21 @@ [[- profile.isStaff ? "yes" : "no" ]] + + + is artist? + + + [[- profile.isArtist ? "yes" : "no" ]] + +

    [[ if (String(user._id) != String(profile._id)) { ]] + [[ } ]]
    -- cgit v1.2.3-70-g09d2