Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove login lock #1840

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions dongtai_web/views/user_login.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/local/env python
import logging
import time
from datetime import timedelta

from captcha.models import CaptchaStore
from django.contrib.auth import authenticate, login
Expand All @@ -12,6 +11,7 @@
from dongtai_common.endpoint import R, UserEndPoint
from dongtai_common.models.user import User
from dongtai_common.utils.request_type import Request
from dongtai_conf.patch import patch_point, to_patch

logger = logging.getLogger("dongtai-webapi")

Expand All @@ -26,6 +26,7 @@ class UserLogin(UserEndPoint):
summary=_("User login"),
tags=[_("User")],
)
@to_patch
def post(self, request: Request):
"""{
'username': "",
Expand All @@ -46,16 +47,9 @@ def post(self, request: Request):
password = request.data["password"]
user: User | None = authenticate(username=username, password=password) # type: ignore
if user is not None:
current_time = timezone.now()
delta = current_time - user.failed_login_time
if (
(user.failed_login_count == 6 and delta < timedelta(minutes=1))
or (user.failed_login_count == 7 and delta < timedelta(minutes=5))
or (user.failed_login_count == 8 and delta < timedelta(minutes=15))
or (user.failed_login_count == 9 and delta < timedelta(minutes=60))
or user.failed_login_count >= 10
):
return R.failure(status=206, msg="账号已被锁定")
user, login_result = patch_point(user, None)
if login_result is not None:
return login_result
user.failed_login_count = 0
user.save()
login(request, user)
Expand Down
Loading