From 7031b7f28bfa7b9a01bc29cf749e8067ec798839 Mon Sep 17 00:00:00 2001 From: xinwen Date: Tue, 27 Oct 2020 18:43:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E4=BF=AE=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E5=87=BA=E7=8E=B00=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/mixins.py | 8 ++++++-- apps/authentication/views/login.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index 8d6b7765a..1d9335743 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -53,7 +53,7 @@ class AuthMixin: ip = ip or get_request_ip(self.request) return ip - def check_is_block(self): + def check_is_block(self, raise_exception=True): if hasattr(self.request, 'data'): username = self.request.data.get("username") else: @@ -61,7 +61,11 @@ class AuthMixin: ip = self.get_request_ip() if is_block_login(username, ip): logger.warn('Ip was blocked' + ': ' + username + ':' + ip) - raise errors.BlockLoginError(username=username, ip=ip) + exception = errors.BlockLoginError(username=username, ip=ip) + if raise_exception: + raise errors.BlockLoginError(username=username, ip=ip) + else: + return exception def decrypt_passwd(self, raw_passwd): # 获取解密密钥,对密码进行解密 diff --git a/apps/authentication/views/login.py b/apps/authentication/views/login.py index 42925b9ff..4210315c5 100644 --- a/apps/authentication/views/login.py +++ b/apps/authentication/views/login.py @@ -87,6 +87,7 @@ class UserLoginView(mixins.AuthMixin, FormView): try: self.check_user_auth(decrypt_passwd=True) except errors.AuthFailedError as e: + e = self.check_is_block(raise_exception=False) or e form.add_error(None, e.msg) ip = self.get_request_ip() cache.set(self.key_prefix_captcha.format(ip), 1, 3600)