redy: bad authentication
This commit is contained in:
parent
33cb16af3f
commit
9c88d1be60
27
public/static/css/rosmorport.css
Normal file
27
public/static/css/rosmorport.css
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* шрифт для лого */
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap');
|
||||||
|
/*@import url('https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap');*/
|
||||||
|
/*@import url('https://fonts.googleapis.com/css2?family=Kurale&display=swap');*/
|
||||||
|
|
||||||
|
/* НАВИГАЦИЯ */
|
||||||
|
.navbar {
|
||||||
|
background: rgb(111,66,193);
|
||||||
|
background: linear-gradient(11deg, rgba(111,66,193,1) 15%, rgba(152,66,193,0.7) 70%);
|
||||||
|
height: 75px;
|
||||||
|
}
|
||||||
|
.navbar > div.container-fluid > a.navbar-brand {
|
||||||
|
font-family: "Lobster", sans-serif;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 11pt;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
background: rgb(33, 20, 56);
|
||||||
|
background: linear-gradient(11deg, rgb(33, 20, 56, 1) 15%, rgba(49, 22, 64, 0.6) 70%);
|
||||||
|
}
|
||||||
|
.modal > .modal-dialog > .modal-content .modal-header,
|
||||||
|
.modal > .modal-dialog > .modal-content .modal-footer {
|
||||||
|
background: whitesmoke;
|
||||||
|
}
|
@ -27,6 +27,7 @@ urlpatterns = [
|
|||||||
re_path(r'^$', views.index),
|
re_path(r'^$', views.index),
|
||||||
re_path(r'^logout$', views.my_logout),
|
re_path(r'^logout$', views.my_logout),
|
||||||
re_path(r'^login$', views.my_login),
|
re_path(r'^login$', views.my_login),
|
||||||
|
re_path(r'^not-auth$', views.not_auth),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Обработчики ошибок
|
# Обработчики ошибок
|
||||||
|
@ -16,7 +16,7 @@ def index(request: HttpRequest) -> HttpResponse:
|
|||||||
# except (TemplateDoesNotExist, TemplateSyntaxError) as e:
|
# except (TemplateDoesNotExist, TemplateSyntaxError) as e:
|
||||||
# # Обработка ошибки отсутствия шаблона
|
# # Обработка ошибки отсутствия шаблона
|
||||||
# return HttpResponse(f"Не нашли шаблон или в нем ошибка \"{e}\".", status=424)
|
# return HttpResponse(f"Не нашли шаблон или в нем ошибка \"{e}\".", status=424)
|
||||||
return render(request, "index.jinja", {})
|
return render(request, template_name="index.jinja", context={})
|
||||||
|
|
||||||
|
|
||||||
def my_logout(request: HttpRequest) -> HttpResponseRedirect:
|
def my_logout(request: HttpRequest) -> HttpResponseRedirect:
|
||||||
@ -26,7 +26,7 @@ def my_logout(request: HttpRequest) -> HttpResponseRedirect:
|
|||||||
:return response: исходящий http-ответ
|
:return response: исходящий http-ответ
|
||||||
"""
|
"""
|
||||||
logout(request)
|
logout(request)
|
||||||
return HttpResponseRedirect('/')
|
return HttpResponseRedirect(redirect_to='/')
|
||||||
|
|
||||||
|
|
||||||
def my_login(request: HttpRequest) -> HttpResponseRedirect:
|
def my_login(request: HttpRequest) -> HttpResponseRedirect:
|
||||||
@ -35,18 +35,27 @@ def my_login(request: HttpRequest) -> HttpResponseRedirect:
|
|||||||
:param
|
:param
|
||||||
:return response: исходящий http-ответ
|
:return response: исходящий http-ответ
|
||||||
"""
|
"""
|
||||||
print(request.POST)
|
try:
|
||||||
if request.method == 'POST':
|
print(request.POST)
|
||||||
username = request.POST.get('username')
|
if request.method == 'POST':
|
||||||
password = request.POST.get('password')
|
user = authenticate(request,
|
||||||
print(username, password)
|
username=request.POST['username'],
|
||||||
user = authenticate(request, username=username, password=password)
|
password=request.POST['password'])
|
||||||
if user is not None:
|
if user is None:
|
||||||
login(request, user)
|
# return HttpResponse('Пользователь не найден', status=304)
|
||||||
# A backend authenticated the credentials
|
return HttpResponseRedirect(redirect_to='/not-auth')
|
||||||
print(f"{user} is authenticated")
|
else:
|
||||||
else:
|
login(request, user)
|
||||||
# No backend authenticated the credentials
|
return HttpResponseRedirect('/')
|
||||||
pass
|
except KeyError:
|
||||||
# request.session['user'] = request.POST.get('login')
|
return HttpResponseRedirect('/')
|
||||||
return HttpResponseRedirect('/')
|
|
||||||
|
|
||||||
|
def not_auth(request: HttpRequest) -> HttpResponse:
|
||||||
|
""" Страница для неавторизованных пользователей
|
||||||
|
|
||||||
|
:param
|
||||||
|
:return response: исходящий http-ответ
|
||||||
|
"""
|
||||||
|
to_template = {"META_REFRESH": "15; url=/"}
|
||||||
|
return render(request, template_name="not_auth.jinja", context=to_template, status=401)
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
<meta name="robots" content="index,follow" />
|
<meta name="robots" content="index,follow" />
|
||||||
<meta name="revisit-after" content="15 days">
|
<meta name="revisit-after" content="15 days">
|
||||||
<meta name="document-state" content="{{ META_DOCUMENT_STATE|default:'Dynamic' }}" />
|
<meta name="document-state" content="{{ META_DOCUMENT_STATE|default:'Dynamic' }}" />
|
||||||
|
<meta http-equiv="refresh" content="{{ META_REFRESH|default:'86400' }}" >
|
||||||
<meta name="format-detection" content="telephone=no" />
|
<meta name="format-detection" content="telephone=no" />
|
||||||
<meta name="theme-color" content="#F5F5F5" /><!-- theme-color предоставляет браузерам цвет CSS для настройки
|
<meta name="theme-color" content="#F5F5F5" /><!-- theme-color предоставляет браузерам цвет CSS для настройки
|
||||||
отображения страницы или окружающего пользовательского интерфейса. -->
|
отображения страницы или окружающего пользовательского интерфейса. -->
|
||||||
@ -38,7 +38,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>{% block BODY %}
|
<body>{% block BODY %}
|
||||||
{% block Top_CSS1 %}{% endblock %}{% block Top_CSS2 %}{% endblock %}{% block Top_CSS3 %}{% endblock %}{% include "blocks/header_nav.jinja" %}
|
{% block Top_CSS1 %}{% endblock %}{% block Top_CSS2 %}{% endblock %}{% block Top_CSS3 %}{% endblock %}{% include "blocks/header_nav.jinja" %}
|
||||||
{# {% block CONTENT %}{% endblock CONTENT %}#}
|
{% block CONTENT %}{% endblock CONTENT %}
|
||||||
{# {% include "blocks/footer.jinja" %} #}{# {% if COOKIES %}#}
|
{# {% include "blocks/footer.jinja" %} #}{# {% if COOKIES %}#}
|
||||||
{# {% include "blocks/accept-cookies.jinja2" %}{% endif %} #}
|
{# {% include "blocks/accept-cookies.jinja2" %}{% endif %} #}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{# ВЕРХНЯЯ НАВИГАЦИЯ #}<nav class="navbar">
|
{# ВЕРХНЯЯ НАВИГАЦИЯ #}<nav class="navbar">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand mb-0 h1" href="\">Тестовое задание Frontend</a>
|
<a class="navbar-brand mb-0 h1" href="/">Тестовое задание Frontend</a>
|
||||||
<div class="navbar-nav ms-auto"><nobr>{% if request.user.is_authenticated %}
|
<div class="navbar-nav ms-auto"><nobr>{% if request.user.is_authenticated %}
|
||||||
<i class="fa-solid fa-user"></i> {{ user }}
|
<i class="fa-solid fa-user"></i> {{ user }}
|
||||||
<a class="btn btn-secondary btn-sm ms-3"href="/logout">выход
|
<a class="btn btn-secondary btn-sm ms-3"href="/logout">выход
|
||||||
@ -12,5 +12,4 @@
|
|||||||
</a>{% endif %}</nobr>
|
</a>{% endif %}</nobr>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>{% include "popup/logon-logout.jinja" %}
|
</nav>{% include "popup/logon-logout.jinja" %}
|
||||||
|
|
28
rosmorport_tsts/templates-django/not_auth.jinja
Normal file
28
rosmorport_tsts/templates-django/not_auth.jinja
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{% extends 'base.jinja' %}
|
||||||
|
|
||||||
|
{% block CONTENT %}<!-- Modal warning / bad login -->
|
||||||
|
<div class="modal fade" id="bad_login_modal" tabindex="-1" aria-labelledby="bad_login_modal_Label" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content shadow">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h3 class="modal-title fs-5" id="bad_login_modal_Label">ошибка аутентификации</h3>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<h1 class="text-danger-emphasis"><i class="fa-regular fa-circle-xmark"></i> Ошибка</h1>
|
||||||
|
<p>Введен неверный логин или пароль.</p>
|
||||||
|
<p>Будьте внимательно после нескольких попыток ваш IP будет заблокирован!</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<a href="/" class="btn btn-primary">Я больше не буду</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock CONTENT %}
|
||||||
|
{% block Top_JS1 %}<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#bad_login_modal').modal('show');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock Top_JS1 %}
|
@ -1,12 +1,12 @@
|
|||||||
<!-- Login/Logout Modal -->
|
<!-- Login/Logout Modal -->
|
||||||
<div class="modal fade" id="login_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="login_modal" tabindex="-1" aria-labelledby="login_modal_Label" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content shadow">
|
<div class="modal-content shadow">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h3 class="modal-title fs-5" id="exampleModalLabel">вход/выход</h3>
|
<h3 class="modal-title fs-5" id="login_modal_Label">вход/выход</h3>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<form action="\login" method="post">
|
<form action="/login" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="input-group flex-nowrap my-4">
|
<div class="input-group flex-nowrap my-4">
|
||||||
|
Loading…
Reference in New Issue
Block a user