From aa0686f35eef7c6b8dc2e657665acb3a3766807d Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Mon, 25 Feb 2019 14:15:15 +0100 Subject: [PATCH] support for xban2 --- depends.txt | 1 + webmail.lua | 27 +++++++++++++++++++++++---- webmail/public/js/service.js | 2 +- webmail/src/api/login.js | 11 ++++++++--- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/depends.txt b/depends.txt index 3a0e02e..709b3a7 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ unified_inventory? default? +xban2? \ No newline at end of file diff --git a/webmail.lua b/webmail.lua index 9c6a1a6..813c92f 100644 --- a/webmail.lua +++ b/webmail.lua @@ -1,3 +1,7 @@ +-- false per default +local disallow_banned_players = minetest.settings:get("webmail.disallow_banned_players") == "true" +local has_xban2_mod = minetest.get_modpath("xban2") + local MP = minetest.get_modpath(minetest.get_current_modname()) local Channel = dofile(MP .. "/util/channel.lua") local channel @@ -8,16 +12,31 @@ local function auth_handler(auth) minetest.log("action", "[webmail] auth: " .. auth.name) local success = false - local entry = handler.get_auth(auth.name) - if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then - success = true + local banned = false + local message = "" + + if disallow_banned_players and has_xban2_mod then + -- check xban db + local xbanentry = xban.find_entry(auth.name) + if xbanentry and xbanentry.banned then + banned = true + message = "Banned!" + end + end + + if not banned then + local entry = handler.get_auth(auth.name) + if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then + success = true + end end channel.send({ type = "auth", data = { name = auth.name, - success = success + success = success, + message = message } }) end diff --git a/webmail/public/js/service.js b/webmail/public/js/service.js index c0268ad..d3aa7f6 100644 --- a/webmail/public/js/service.js +++ b/webmail/public/js/service.js @@ -37,7 +37,7 @@ service.login = function(username, password){ //fetch mails after login service.fetchMails(); } else { - state.errorMsg = "Login failed!"; + state.errorMsg = "Login failed: " + result.message; } }) .catch(function(err){ diff --git a/webmail/src/api/login.js b/webmail/src/api/login.js index 7977f93..45aa220 100644 --- a/webmail/src/api/login.js +++ b/webmail/src/api/login.js @@ -17,12 +17,17 @@ app.post('/api/login', jsonParser, function(req, res){ doLogin(req.body.username, req.body.password) .then(result => { - var t = token.sign({ - username: req.body.username - }); + var t; + + if (result.success){ + t = token.sign({ + username: req.body.username + }); + } res.json({ success: result.success, + message: result.message, token: t }); })