From 45902ae01278723f11062bed12ea44fe4f042df6 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Sun, 5 Nov 2017 18:12:50 +0100 Subject: [PATCH] Fix a bug when trying to authenticate with a non existing user --- core/admin/mailu/internal/nginx.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/core/admin/mailu/internal/nginx.py b/core/admin/mailu/internal/nginx.py index dc834cb9..7b84630d 100644 --- a/core/admin/mailu/internal/nginx.py +++ b/core/admin/mailu/internal/nginx.py @@ -37,20 +37,21 @@ def handle_authentication(headers): password = urllib.parse.unquote(headers["Auth-Pass"]) ip = urllib.parse.unquote(headers["Client-Ip"]) user = models.User.query.get(user_email) - for token in user.tokens: - if (token.check_password(password) and - (not token.ip or token.ip == ip)): - return { - "Auth-Status": "OK", - "Auth-Server": server, - "Auth-Port": port - } - if user and user.check_password(password): - return { - "Auth-Status": "OK", - "Auth-Server": server, - "Auth-Port": port - } + if user: + for token in user.tokens: + if (token.check_password(password) and + (not token.ip or token.ip == ip)): + return { + "Auth-Status": "OK", + "Auth-Server": server, + "Auth-Port": port + } + if user.check_password(password): + return { + "Auth-Status": "OK", + "Auth-Server": server, + "Auth-Port": port + } else: status, code = get_status(protocol, "authentication") return {