update : 31.03.2025 10:57:21,62
This commit is contained in:
parent
09e7ad82dd
commit
729c14921c
@ -4,6 +4,8 @@ from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from apps.util import generalmodule
|
||||
from sabron.util import logging
|
||||
|
||||
from users.models import Profile
|
||||
|
||||
|
||||
@ -32,17 +34,20 @@ def user_login(request):
|
||||
user = authenticate(username=username, password=password)
|
||||
if user:
|
||||
if user_api(request, user):
|
||||
text_error = "API пользователь не имеет доступ к в систему"
|
||||
logging.authorization(text_error,request)
|
||||
context = {
|
||||
"error": True,
|
||||
"comment": "API пользователь не имеет доступ к Личному Кабинету",
|
||||
"comment": text_error,
|
||||
}
|
||||
messages.error(
|
||||
request, "Пользователь не имеет доступ к Личному Кабинету"
|
||||
request, text_error
|
||||
)
|
||||
return render(request, "registration/login.html", context)
|
||||
|
||||
if user_block(request, user):
|
||||
login(request, user)
|
||||
logging.authorization(f"Успешный вход : {username} ",request)
|
||||
context = {
|
||||
"user": user,
|
||||
"login": username,
|
||||
@ -50,26 +55,32 @@ def user_login(request):
|
||||
}
|
||||
return HttpResponseRedirect("/", context)
|
||||
else:
|
||||
text_error = "Пользователь заблокирован"
|
||||
logging.authorization(text_error,request)
|
||||
context = {
|
||||
"error": True,
|
||||
"login": username,
|
||||
"comment": "Пользователь заблокирован",
|
||||
"comment": text_error,
|
||||
}
|
||||
messages.error(request, "Пользователь заблокирован")
|
||||
messages.error(request, text_error)
|
||||
return render(request, "registration/login.html", context)
|
||||
else:
|
||||
text_error = "Не верный логин или пароль"
|
||||
logging.authorization(text_error,request)
|
||||
context = {
|
||||
"error": True,
|
||||
"login": username,
|
||||
"comment": "Не верный логин или пароль",
|
||||
"comment": text_error,
|
||||
}
|
||||
messages.error(request, "Не верный логин или пароль")
|
||||
messages.error(request, text_error)
|
||||
return render(request, "registration/login.html", context)
|
||||
else:
|
||||
if request.user.is_anonymous:
|
||||
text_error = "Анонимный вход запрещен"
|
||||
logging.authorization(text_error,request)
|
||||
context = {
|
||||
"error": False,
|
||||
"comment": "",
|
||||
"comment": text_error,
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
|
||||
|
||||
@ -48,6 +48,12 @@ def set():
|
||||
os.mkdir(settings.BASE_DIR + "/log/log")
|
||||
except OSError:
|
||||
return
|
||||
if not os.path.exists(settings.BASE_DIR + "/log/authorization"):
|
||||
try:
|
||||
os.mkdir(settings.BASE_DIR + "/log/authorization")
|
||||
except OSError:
|
||||
return
|
||||
|
||||
if not os.path.exists(settings.MEDIA_ROOT + "/tgbot"):
|
||||
try:
|
||||
os.mkdir(settings.MEDIA_ROOT + "/tgbot")
|
||||
@ -55,6 +61,42 @@ def set():
|
||||
return
|
||||
|
||||
|
||||
def authorization(message,request):
|
||||
meta = request.META
|
||||
print(meta)
|
||||
if 'HTTP_X_REAL_IP' not in meta:
|
||||
meta.update(HTTP_X_REAL_IP='127.0.0.1')
|
||||
message = message + "\n[" + meta['HTTP_X_REAL_IP'] + "] : " + meta['QUERY_STRING'] + "\n" + str(request.headers).replace("', '","'\n '") + "\n"
|
||||
message = message + "{\n"
|
||||
for mt in meta:
|
||||
try:
|
||||
message = message + "'" + str(mt) + "':'" + str(meta[mt]) + "'\n"
|
||||
except Exception as err:
|
||||
error('Error : updateMeta' + str(err))
|
||||
|
||||
message = message + "\n}"
|
||||
message = message + "******************************************************\n"
|
||||
DirLogs = settings.BASE_DIR + "/log/authorization"
|
||||
if not os.path.exists(DirLogs):
|
||||
try:
|
||||
os.mkdir(DirLogs)
|
||||
except OSError:
|
||||
return
|
||||
date = datetime.now()
|
||||
month = "0" if date.month < 10 else ""
|
||||
month += str(date.month)
|
||||
day = "0" if date.day < 10 else ""
|
||||
day += str(date.day)
|
||||
StrDate = "%s%s%s" % (str(date.year), month, day)
|
||||
file = open(DirLogs + "/authorization_" + StrDate + ".log", "a")
|
||||
my_file = File(file)
|
||||
my_file.write(
|
||||
"[%s]: %s\n" % (str(datetime.now().strftime("%d-%m-%Y %H:%M:%S")), str(message))
|
||||
)
|
||||
my_file.closed
|
||||
file.closed
|
||||
|
||||
|
||||
def message(message):
|
||||
DirLogs = settings.BASE_DIR + "/log"
|
||||
if not os.path.exists(DirLogs):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user