mirror of https://github.com/calzoneman/sync.git
Limit user registrations
This commit is contained in:
parent
23acdd7613
commit
55b6e99896
|
@ -57,6 +57,8 @@ youtube-v2-key: ''
|
||||||
channel-save-interval: 5
|
channel-save-interval: 5
|
||||||
# Limit for the number of channels a user can register
|
# Limit for the number of channels a user can register
|
||||||
max-channels-per-user: 5
|
max-channels-per-user: 5
|
||||||
|
# Limit for the number of accounts an IP address can register
|
||||||
|
max-accounts-per-ip: 5
|
||||||
# Minimum number of seconds between guest logins from the same IP
|
# Minimum number of seconds between guest logins from the same IP
|
||||||
guest-login-delay: 60
|
guest-login-delay: 60
|
||||||
# Block known Tor IP addresses
|
# Block known Tor IP addresses
|
||||||
|
|
|
@ -50,6 +50,7 @@ var defaults = {
|
||||||
"youtube-v2-key": "",
|
"youtube-v2-key": "",
|
||||||
"channel-save-interval": 5,
|
"channel-save-interval": 5,
|
||||||
"max-channels-per-user": 5,
|
"max-channels-per-user": 5,
|
||||||
|
"max-accounts-per-ip": 5,
|
||||||
"guest-login-delay": 60,
|
"guest-login-delay": 60,
|
||||||
"enable-tor-blocker": true,
|
"enable-tor-blocker": true,
|
||||||
stats: {
|
stats: {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
var $util = require("../utilities");
|
var $util = require("../utilities");
|
||||||
var bcrypt = require("bcrypt");
|
var bcrypt = require("bcrypt");
|
||||||
var db = require("../database");
|
var db = require("../database");
|
||||||
|
var Config = require("../config");
|
||||||
|
|
||||||
var registrationLock = {};
|
var registrationLock = {};
|
||||||
var blackHole = function () { };
|
var blackHole = function () { };
|
||||||
|
@ -98,7 +99,21 @@ module.exports = {
|
||||||
// on the same user account
|
// on the same user account
|
||||||
registrationLock[lname] = true;
|
registrationLock[lname] = true;
|
||||||
|
|
||||||
this.isUsernameTaken(name, function (err, taken) {
|
this.getAccounts(ip, function (err, accts) {
|
||||||
|
if (err) {
|
||||||
|
delete registrationLock[lname];
|
||||||
|
callback(err, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accts.length >= Config.get("max-accounts-per-ip")) {
|
||||||
|
delete registrationLock[lname];
|
||||||
|
callback("You have registered too many accounts from this "+
|
||||||
|
"computer.", null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.isUsernameTaken(name, function (err, taken) {
|
||||||
if (err) {
|
if (err) {
|
||||||
delete registrationLock[lname];
|
delete registrationLock[lname];
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
|
@ -136,6 +151,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -496,5 +512,17 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
db.query("SELECT * FROM `channels` WHERE owner=?", [name], callback);
|
db.query("SELECT * FROM `channels` WHERE owner=?", [name], callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all names registered from a given IP
|
||||||
|
*/
|
||||||
|
getAccounts: function (ip, callback) {
|
||||||
|
if (typeof callback !== "function") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.query("SELECT name,global_rank FROM `users` WHERE `ip`=?", [ip],
|
||||||
|
callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -139,6 +139,7 @@ function handleRegisterPage(req, res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendJade(res, "register", {
|
sendJade(res, "register", {
|
||||||
registered: false,
|
registered: false,
|
||||||
registerError: false
|
registerError: false
|
||||||
|
|
Loading…
Reference in New Issue