Skip to content

Commit

Permalink
[api] [refactor] Email now required + New pricing
Browse files Browse the repository at this point in the history
  * `User.email` is now a required field
  * Adds registration page for account name
  * Adds screen for upgrading legacy accounts
    * Legacy accounts must upgrade
    * API access will remain
    * Website access will be locked until register
  * Adds new pricing plans
  * Improves test coverage for signups / logins
  * Addresses: #265, #126
  • Loading branch information
Marak committed Nov 5, 2017
1 parent 562bcb8 commit 2f625be
Show file tree
Hide file tree
Showing 32 changed files with 1,328 additions and 601 deletions.
5 changes: 5 additions & 0 deletions lib/helpers/numberWithCommas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function numberWithCommas (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

module.exports = numberWithCommas;
23 changes: 18 additions & 5 deletions lib/resources/servicePlan.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
module.exports = {
"free": {
"hits": 1000,
"concurrency": 2
"concurrency": 2,
"cost": "$0.00"
},
"premium": {
"hits": 10000,
"concurrency": 4
"concurrency": 4,
"stripe_label": 'BASIC_HOSTING_PLAN_10',
"cost": "$10.00"
},
"pro": {
"advanced": {
"hits": 50000,
"concurrency": 10
"concurrency": 16,
"stripe_label": 'BASIC_HOSTING_PLAN_20',
"cost": "$25.00"
},
"pro": {
"hits": 100000,
"concurrency": 8,
"stripe_label": 'BASIC_HOSTING_PLAN_50',
"cost": "$50.00"
},
"business": {
"hits": 1000000,
"concurrency": 50
"concurrency": 32,
"stripe_label": 'BASIC_HOSTING_PLAN_100',
"cost": "$200.00"
}
};
10 changes: 9 additions & 1 deletion lib/resources/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ user.property('env', 'object');
user.property('referredBy', 'string');

// user.property('dedicatedSignup', 'object');
user.schema.properties.email.required = false;
user.schema.properties.name.required = false;
user.schema.properties.email.required = true;
user.schema.properties.password.required = false;

user.property('stripeID', 'string');
Expand Down Expand Up @@ -54,6 +55,7 @@ user.on('login', function (data) {
name: "api-access-key",
owner: data.name || data.username.toLowerCase()
};
// will only create key if it doesn't already exist
keys.findOne(_query, function(err, key){
if (err) {
_query.id = data.id;
Expand All @@ -62,6 +64,12 @@ user.on('login', function (data) {
});
});

// when a user registers an account name
user.on('register', function (data) {
// TODO: create a new subdomain for that user ?
// Remark: Instead of automatically adding subdomains, allow user to register it easily
});

/* not working?
user.after('auth', function (data, next) {
console.log('after auth', data)
Expand Down
11 changes: 10 additions & 1 deletion lib/server/routeHandlers/loginCallback.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var user = require('../../resources/user');
var metric = require('../../resources/metric');

module['exports'] = function (req, res) {
module['exports'] = function loginCallback (req, res) {

var referredBy = req.session.referredBy || "";
var redirectTo = req.session.redirectTo || "/services";
Expand Down Expand Up @@ -32,6 +32,10 @@ module['exports'] = function (req, res) {
} catch(err) {
// do nothing
}

// what happens if we have a conflicting namespace here between github and hook.io?
// i believe it will result in an error due to req.session.user already existing in hook.io data
// todo: figure out a way for github users to register accounts if their github name is already taken by another user on hook.io
user.create({
name: req.session.user,
email: mail,
Expand All @@ -49,7 +53,12 @@ module['exports'] = function (req, res) {
} else {
// assign paid status based on existing user document
req.session.paidStatus = result[0].paidStatus;
req.session.servicePlan = result[0].servicePlan || 'free';
req.session.email = result[0].email;

// shouldn't this be assigned based on the github user name?

// req.session.user = result[0].name;
req.session.hookAccessKey = result[0].hookAccessKey;
user.emit('login', result[0]);
var u = result[0];
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"mschema": "https://github.com/mschema/mschema/tarball/master",
"mschema-forms": "https://github.com/mschema/mschema-forms/tarball/master",
"mschema-rpc": "https://github.com/mschema/mschema-rpc/tarball/master",
"ms": "2.0.0",
"mustache": "^0.8.2",
"nano": "^6.2.0",
"node-slug": "0.0.2",
Expand Down
3 changes: 1 addition & 2 deletions public/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ label {
margin-bottom: 30px;
}

/* hide for now, too frequently popping up */
.emailReminder {
display: none;
display: block;
}

.emailReminder .content {
Expand Down
2 changes: 1 addition & 1 deletion public/css/responsive.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ margin-top:0px;

/* small mobile :320px. */
@media (max-width: 767px) {
.container {width:300px}
.container {width:100%}
.header_nav{
display:none;
}
Expand Down
15 changes: 11 additions & 4 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2700,8 +2700,13 @@ span.member-role {

.button_set_plain {
text-align: right;
/*
margin: 20px 0px 0px;
padding: 8px 0px;
*/
padding: 0px;
margin: 0px;
width: 75px;
border-top: none;
}
.button_set_plain p {
Expand All @@ -2711,16 +2716,18 @@ span.member-role {
background: transparent;
border: 1px solid #d7d7d7;
color: #868686;
padding: 7px 18px 5px;
font-size: 16px;
/*padding: 7px 18px 5px;*/
}
.button_set_plain .newsl_button button span {
background: transparent;
/*background: transparent;*/
background-color: #0F99DE;
border: 1px solid #d7d7d7;
color: #868686;
color: #FFF;
}
.button_set_plain .newsl_button button:hover span {
border-color: #0F99DE;
background-color: #0F99DE;
background-color: #000;
color: #fff;
}
.button_set_plain .newsl_button {
Expand Down
49 changes: 49 additions & 0 deletions scripts/tools/clear-all-billings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var config = require('../../config');

var billing = require('../../lib/resources/billing');
var user = require('../../lib/resources/user');

var colors = require('colors');

billing.persist(config.couch);
user.persist(config.couch);

user.findOne({
name: 'bobby'
}, function(err, _u){
if(err) {
throw err;
}
_u.servicePlan = "free";
_u.save(function(err){
if(err) {
throw err;
}
clearBillings();
})
});

function clearBillings () {
billing.find({ owner: 'bobby' }, function(err, results){

// billing.all(function(err, results){
if(err) {
throw err;
}
console.log(results)
function destroy () {
if (results.length === 0) {
process.exit();
}
var result = results.pop();
console.log(result.owner.toLowerCase())
result.destroy(function(err, res){
if (err) {
throw err;
}
destroy();
});
}
destroy();
});
}
Loading

0 comments on commit 2f625be

Please sign in to comment.