Finished up with IP-Ban functionality on the back-end. Just need to finish up with UI.
This commit is contained in:
parent
756c42ceaa
commit
977e8e1e2e
16 changed files with 284 additions and 67 deletions
|
|
@ -14,6 +14,9 @@ GNU Affero General Public License for more details.
|
|||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//Config
|
||||
const config = require('../../config.json');
|
||||
|
||||
//At some point this will be a bit more advanced, right now it's just a placeholder :P
|
||||
module.exports.errorHandler = function(res, msg, type = "Generic", status = 400){
|
||||
//Some controllers do things after sending headers, for those, we should remain silent
|
||||
|
|
@ -24,11 +27,23 @@ module.exports.errorHandler = function(res, msg, type = "Generic", status = 400)
|
|||
}
|
||||
|
||||
module.exports.exceptionHandler = function(res, err){
|
||||
//If we're being verbose
|
||||
if(config.verbose){
|
||||
//Log the error
|
||||
console.log(err)
|
||||
}
|
||||
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
module.exports.errorHandler(res, err.message, "Caught Exception");
|
||||
}
|
||||
|
||||
module.exports.socketExceptionHandler = function(socket, err){
|
||||
//If we're being verbose
|
||||
if(config.verbose){
|
||||
//Log the error
|
||||
console.log(err)
|
||||
}
|
||||
|
||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||
return socket.emit("error", {errors: [{type: "Caught Exception", msg: err.message, date: new Date()}]});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,15 @@ module.exports.authenticateSession = async function(user, pass, req){
|
|||
//Grab previous attempts
|
||||
const attempt = failedAttempts.get(user);
|
||||
|
||||
//Look for ban by IP
|
||||
const ipBanDB = await userBanModel.checkBanByIP(req.ip);
|
||||
|
||||
//If this ip is randy bobandy
|
||||
if(ipBanDB != null){
|
||||
//tell it to fuck off
|
||||
throw new Error(`The IP address you are trying to login from has been banned.`);
|
||||
}
|
||||
|
||||
//If we have failed attempts
|
||||
if(attempt != null){
|
||||
//If we have more failed attempts than allowed
|
||||
|
|
@ -53,13 +62,15 @@ module.exports.authenticateSession = async function(user, pass, req){
|
|||
|
||||
//Authenticate the session
|
||||
const userDB = await userModel.authenticate(user, pass);
|
||||
const banDB = await userBanModel.checkBanByUserDoc(userDB);
|
||||
|
||||
//Check for user ban
|
||||
const userBanDB = await userBanModel.checkBanByUserDoc(userDB);
|
||||
|
||||
//If the user is banned
|
||||
if(banDB){
|
||||
if(userBanDB){
|
||||
//Make the number a little prettier despite the lack of precision since we're not doing calculations here :P
|
||||
const expiration = banDB.getDaysUntilExpiration() < 1 ? 0 : banDB.getDaysUntilExpiration();
|
||||
if(banDB.permanent){
|
||||
const expiration = userBanDB.getDaysUntilExpiration() < 1 ? 0 : userBanDB.getDaysUntilExpiration();
|
||||
if(userBanDB.permanent){
|
||||
throw new Error(`Your account has been permanently banned, and will be nuked from the database in: ${expiration} day(s)`);
|
||||
}else{
|
||||
throw new Error(`Your account has been temporarily banned, and will be reinstated in: ${expiration} day(s)`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue