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
|
|
@ -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