Commit 62c1b488 authored by ibuler's avatar ibuler

[Bugfix] 修改登陆错误

parent 39f7ac2e
...@@ -26,6 +26,7 @@ from users.utils import ( ...@@ -26,6 +26,7 @@ from users.utils import (
) )
from ..signals import post_auth_success, post_auth_failed from ..signals import post_auth_success, post_auth_failed
from .. import forms from .. import forms
from .. import const
__all__ = [ __all__ = [
...@@ -81,7 +82,7 @@ class UserLoginView(FormView): ...@@ -81,7 +82,7 @@ class UserLoginView(FormView):
user = form.get_user() user = form.get_user()
# user password expired # user password expired
if user.password_has_expired: if user.password_has_expired:
reason = LoginLog.REASON_PASSWORD_EXPIRED reason = const.password_expired
self.send_auth_signal(success=False, username=user.username, reason=reason) self.send_auth_signal(success=False, username=user.username, reason=reason)
return self.render_to_response(self.get_context_data(password_expired=True)) return self.render_to_response(self.get_context_data(password_expired=True))
...@@ -96,7 +97,7 @@ class UserLoginView(FormView): ...@@ -96,7 +97,7 @@ class UserLoginView(FormView):
# write login failed log # write login failed log
username = form.cleaned_data.get('username') username = form.cleaned_data.get('username')
exist = User.objects.filter(username=username).first() exist = User.objects.filter(username=username).first()
reason = LoginLog.REASON_PASSWORD if exist else LoginLog.REASON_NOT_EXIST reason = const.password_failed if exist else const.user_not_exist
# limit user login failed count # limit user login failed count
ip = get_request_ip(self.request) ip = get_request_ip(self.request)
increase_login_failed_count(username, ip) increase_login_failed_count(username, ip)
...@@ -166,7 +167,7 @@ class UserLoginOtpView(FormView): ...@@ -166,7 +167,7 @@ class UserLoginOtpView(FormView):
else: else:
self.send_auth_signal( self.send_auth_signal(
success=False, username=user.username, success=False, username=user.username,
reason=LoginLog.REASON_MFA reason=const.mfa_failed
) )
form.add_error( form.add_error(
'otp_code', _('MFA code invalid, or ntp sync server time') 'otp_code', _('MFA code invalid, or ntp sync server time')
......
...@@ -215,7 +215,7 @@ LOGGING = { ...@@ -215,7 +215,7 @@ LOGGING = {
'format': '%(levelname)s %(message)s' 'format': '%(levelname)s %(message)s'
}, },
'syslog': { 'syslog': {
'format': '%(name)s: %(message)s' 'format': 'jumpserver: %(message)s'
}, },
'msg': { 'msg': {
'format': '%(message)s' 'format': '%(message)s'
...@@ -249,6 +249,11 @@ LOGGING = { ...@@ -249,6 +249,11 @@ LOGGING = {
'backupCount': 7, 'backupCount': 7,
'filename': ANSIBLE_LOG_FILE, 'filename': ANSIBLE_LOG_FILE,
}, },
'syslog': {
'level': 'INFO',
'class': 'logging.NullHandler',
'formatter': 'syslog'
},
}, },
'loggers': { 'loggers': {
'django': { 'django': {
...@@ -257,17 +262,17 @@ LOGGING = { ...@@ -257,17 +262,17 @@ LOGGING = {
'level': LOG_LEVEL, 'level': LOG_LEVEL,
}, },
'django.request': { 'django.request': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file', 'syslog'],
'level': LOG_LEVEL, 'level': LOG_LEVEL,
'propagate': False, 'propagate': False,
}, },
'django.server': { 'django.server': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file', 'syslog'],
'level': LOG_LEVEL, 'level': LOG_LEVEL,
'propagate': False, 'propagate': False,
}, },
'jumpserver': { 'jumpserver': {
'handlers': ['console', 'file'], 'handlers': ['console', 'file', 'syslog'],
'level': LOG_LEVEL, 'level': LOG_LEVEL,
}, },
'ops.ansible_api': { 'ops.ansible_api': {
...@@ -278,6 +283,10 @@ LOGGING = { ...@@ -278,6 +283,10 @@ LOGGING = {
'handlers': ['console', 'file'], 'handlers': ['console', 'file'],
'level': "INFO", 'level': "INFO",
}, },
'jms_audits': {
'handlers': ['syslog'],
'level': 'INFO'
},
# 'django.db': { # 'django.db': {
# 'handlers': ['console', 'file'], # 'handlers': ['console', 'file'],
# 'level': 'DEBUG' # 'level': 'DEBUG'
...@@ -290,17 +299,11 @@ SYSLOG_ENABLE = False ...@@ -290,17 +299,11 @@ SYSLOG_ENABLE = False
if CONFIG.SYSLOG_ADDR != '' and len(CONFIG.SYSLOG_ADDR.split(':')) == 2: if CONFIG.SYSLOG_ADDR != '' and len(CONFIG.SYSLOG_ADDR.split(':')) == 2:
host, port = CONFIG.SYSLOG_ADDR.split(':') host, port = CONFIG.SYSLOG_ADDR.split(':')
SYSLOG_ENABLE = True SYSLOG_ENABLE = True
LOGGING['handlers']['syslog'] = { LOGGING['handlers']['syslog'].update({
'level': 'INFO',
'class': 'logging.handlers.SysLogHandler', 'class': 'logging.handlers.SysLogHandler',
'facility': CONFIG.SYSLOG_FACILITY, 'facility': CONFIG.SYSLOG_FACILITY,
'address': (host, int(port)), 'address': (host, int(port)),
'formatter': 'syslog' })
}
LOGGING['loggers']['jms'] = {
'handlers': ['syslog'],
'level': 'INFO'
}
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/ # https://docs.djangoproject.com/en/1.10/topics/i18n/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment