Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Aug 14, 2024
1 parent 96b59b7 commit b85dd6b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions seahub/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from seahub.utils.user_permissions import get_user_role
from seahub.utils.auth import get_login_bg_image_path
from seahub.organizations.models import OrgSAMLConfig
from seahub.sysadmin_extra.models import UserLoginLog

from constance import config

Expand Down Expand Up @@ -77,7 +78,16 @@ def log_user_in(request, user, redirect_to):

# Okay, security checks complete. Log the user in.
auth_login(request, user)

# if UserLoginLog.objects.filter(username=user.username).count() == 1:
# email_template_name = 'registration/password_change_email.html'
# send_to = email2contact_email(request.user.username)
# site_name = get_site_name()
# c = {
# 'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# }
# send_html_email(_("Successfully Changed Password on %s") % site_name,
# email_template_name, c, None,
# [send_to])
return HttpResponseRedirect(redirect_to)

def _handle_login_form_valid(request, user, redirect_to, remember_me):
Expand Down Expand Up @@ -111,15 +121,12 @@ def login(request, template_name='registration/login.html',
return HttpResponseRedirect(reverse(redirect_if_logged_in))

ip = get_remote_ip(request)
print('ip',ip)
print(request.headers.get('User-Agent',None))
if request.method == "POST":
login = request.POST.get('login', '').strip()
failed_attempt = get_login_failed_attempts(username=login, ip=ip)
remember_me = True if request.POST.get('remember_me',
'') == 'on' else False
redirect_to = request.POST.get(redirect_field_name, '') or redirect_to

# check the form
used_captcha_already = False
if bool(config.FREEZE_USER_ON_LOGIN_FAILED) is True:
Expand All @@ -130,7 +137,6 @@ def login(request, template_name='registration/login.html',
used_captcha_already = True
else:
form = authentication_form(data=request.POST)

if form.is_valid():
return _handle_login_form_valid(request, form.get_user(),
redirect_to, remember_me)
Expand Down Expand Up @@ -486,16 +492,6 @@ def password_change(request, template_name='registration/password_change_form.ht
form = password_change_form(user=request.user, data=request.POST)
if form.is_valid():
form.save()
print('进入')
email_template_name = 'registration/password_change_email.html'
send_to = email2contact_email(request.user.username)
site_name = get_site_name()
c = {
'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
}
send_html_email(_("Successfully Changed Password on %s") % site_name,
email_template_name, c, None,
[send_to])

if request.session.get('force_passwd_change', False):
del request.session['force_passwd_change']
Expand Down

0 comments on commit b85dd6b

Please sign in to comment.