login/logout -- redy
This commit is contained in:
parent
c543cc2ecd
commit
33cb16af3f
@ -137,6 +137,8 @@ FIRST_DAY_OF_WEEK = 1 # первый день неде
|
||||
SHORT_DATE_FORMAT = '%Y-%m-%d'
|
||||
SHORT_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
||||
|
||||
APPEND_SLASH = False
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
||||
|
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
URL configuration for rosmorport_tsts project.
|
||||
|
||||
@ -15,8 +16,22 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
from django.conf.urls.static import static
|
||||
from rosmorport_tsts.settings import *
|
||||
from rosmorport_tsts import views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
re_path(r'^$', views.index),
|
||||
re_path(r'^logout$', views.my_logout),
|
||||
re_path(r'^login$', views.my_login),
|
||||
]
|
||||
|
||||
# Обработчики ошибок
|
||||
# handler404 = 'web.views.handler404'
|
||||
# handler500 = 'web.views.handler500'
|
||||
|
||||
if DEBUG:
|
||||
urlpatterns += static(MEDIA_URL, document_root=MEDIA_ROOT)
|
52
rosmorport_tsts/rosmorport_tsts/views.py
Normal file
52
rosmorport_tsts/rosmorport_tsts/views.py
Normal file
@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.shortcuts import render, HttpResponseRedirect
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.template.exceptions import TemplateDoesNotExist, TemplateSyntaxError
|
||||
|
||||
|
||||
def index(request: HttpRequest) -> HttpResponse:
|
||||
""" тест индексной страницы
|
||||
|
||||
:param
|
||||
:return response: исходящий http-ответ
|
||||
"""
|
||||
# try:
|
||||
# return render(request, "index.jinja", {})
|
||||
# except (TemplateDoesNotExist, TemplateSyntaxError) as e:
|
||||
# # Обработка ошибки отсутствия шаблона
|
||||
# return HttpResponse(f"Не нашли шаблон или в нем ошибка \"{e}\".", status=424)
|
||||
return render(request, "index.jinja", {})
|
||||
|
||||
|
||||
def my_logout(request: HttpRequest) -> HttpResponseRedirect:
|
||||
""" Разлогируем пользователя
|
||||
|
||||
:param
|
||||
:return response: исходящий http-ответ
|
||||
"""
|
||||
logout(request)
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
def my_login(request: HttpRequest) -> HttpResponseRedirect:
|
||||
""" Логиним пользователя
|
||||
|
||||
:param
|
||||
:return response: исходящий http-ответ
|
||||
"""
|
||||
print(request.POST)
|
||||
if request.method == 'POST':
|
||||
username = request.POST.get('username')
|
||||
password = request.POST.get('password')
|
||||
print(username, password)
|
||||
user = authenticate(request, username=username, password=password)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
# A backend authenticated the credentials
|
||||
print(f"{user} is authenticated")
|
||||
else:
|
||||
# No backend authenticated the credentials
|
||||
pass
|
||||
# request.session['user'] = request.POST.get('login')
|
||||
return HttpResponseRedirect('/')
|
@ -21,41 +21,30 @@
|
||||
<meta name="document-state" content="{{ META_DOCUMENT_STATE|default:'Dynamic' }}" />
|
||||
|
||||
<meta name="format-detection" content="telephone=no" />
|
||||
<meta name="theme-color" content="#F5F5F5" />{# theme-color предоставляет браузерам цвет CSS для настройки
|
||||
отображения страницы или окружающего пользовательского интерфейса.#}
|
||||
<link rel="canonical" href="{% block canonical %}{% endblock %}">{#
|
||||
<meta name="theme-color" content="#F5F5F5" /><!-- theme-color предоставляет браузерам цвет CSS для настройки
|
||||
отображения страницы или окружающего пользовательского интерфейса. -->
|
||||
<link rel="canonical" href="{% block canonical %}{% endblock %}">
|
||||
<!-- Favicons -->
|
||||
|
||||
<link rel="icon" type="image/svg+xml" href="{% static 'svgs/favicon.svg' %}" /> #}
|
||||
{# <link rel="icon" type="image/svg+xml" href="{% static 'svgs/favicon.svg' %}" /> #}
|
||||
<link rel="icon" type="image/png" href="{% static 'img/favicon-96.png' %}" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="{% static 'img/favicon.ico' %}" />{#
|
||||
|
||||
<link rel="shortcut icon" type="image/x-icon" href="{% static 'img/favicon.ico' %}" />
|
||||
<!-- css -->
|
||||
|
||||
#}
|
||||
<link rel="stylesheet" href="{{ static('css/bootstrap.min.css') }}" />
|
||||
<link rel="stylesheet" href="{{ static('css/all.min.css') }}" />
|
||||
<link rel="stylesheet" href="{{ static('css/phonebook.css') }}" />{% block META_OG %}{% endblock %}{#
|
||||
<meta name="generator" content="Microsoft FrontPage 1.0" />
|
||||
<meta name="generator" content="RSVO.RU -- 0.01β by Python/Django" />
|
||||
#}{#
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" />
|
||||
<link rel="stylesheet" href="{% static 'css/all.min.css' %}" />
|
||||
<link rel="stylesheet" href="{% static 'css/rosmorport.css' %}" />
|
||||
<!-- jQuery JavaScript -->
|
||||
|
||||
#}
|
||||
<script type="text/javascript" src="{{ static('js/jquery-3.6.0.min.js') }}"></script>
|
||||
<script type="text/javascript" src="{{ static('js/js.cookie.min.js') }}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/jquery-3.7.1.min.js' %}"></script>
|
||||
{# <script type="text/javascript" src="{% static 'js/js.cookie.min.js' %}"></script> #}
|
||||
</head>
|
||||
<body class="night">{% block BODY %}
|
||||
{% block Top_CSS1 %}{% endblock %}{% block Top_CSS2 %}{% endblock %}{% block Top_CSS3 %}{% endblock %}{% include "blocks/header_nav.jinja2" %}{% block CONTENT %}{% endblock CONTENT %}
|
||||
{% include "blocks/footer.jinja2" %}{% if COOKIES %}
|
||||
{% include "blocks/accept-cookies.jinja2" %}{% endif %}
|
||||
<body>{% block BODY %}
|
||||
{% block Top_CSS1 %}{% endblock %}{% block Top_CSS2 %}{% endblock %}{% block Top_CSS3 %}{% endblock %}{% include "blocks/header_nav.jinja" %}
|
||||
{# {% block CONTENT %}{% endblock CONTENT %}#}
|
||||
{# {% include "blocks/footer.jinja" %} #}{# {% if COOKIES %}#}
|
||||
{# {% include "blocks/accept-cookies.jinja2" %}{% endif %} #}
|
||||
|
||||
{% block Top_JS1 %}{% endblock Top_JS1 %}{% block Top_JS2 %}{% endblock Top_JS2 %}{% block Top_JS3 %}{% endblock Top_JS3 %}{#
|
||||
{% block Top_JS1 %}{% endblock Top_JS1 %}{% block Top_JS2 %}{% endblock Top_JS2 %}{% block Top_JS3 %}{% endblock Top_JS3 %}
|
||||
|
||||
<!-- Bootstrap JavaScript -->
|
||||
<!-- script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script -->
|
||||
|
||||
#}<script type="text/javascript" src="{{ static('js/bootstrap.bundle.min.js') }}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
|
||||
{% endblock BODY %}</body>
|
||||
</html>
|
16
rosmorport_tsts/templates-django/blocks/header_nav.jinja
Normal file
16
rosmorport_tsts/templates-django/blocks/header_nav.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{# ВЕРХНЯЯ НАВИГАЦИЯ #}<nav class="navbar">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand mb-0 h1" href="\">Тестовое задание Frontend</a>
|
||||
<div class="navbar-nav ms-auto"><nobr>{% if request.user.is_authenticated %}
|
||||
<i class="fa-solid fa-user"></i> {{ user }}
|
||||
<a class="btn btn-secondary btn-sm ms-3"href="/logout">выход
|
||||
<i class="fa-solid fa-person-walking-arrow-right"></i>
|
||||
</a>{% else %}
|
||||
<a class="btn btn-secondary btn-sm" href="#"
|
||||
data-bs-toggle="modal" data-bs-target="#login_modal">
|
||||
<i class="fa-solid fa-right-to-bracket"></i> вход
|
||||
</a>{% endif %}</nobr>
|
||||
</div>
|
||||
</div>
|
||||
</nav>{% include "popup/logon-logout.jinja" %}
|
||||
|
1
rosmorport_tsts/templates-django/index.jinja
Normal file
1
rosmorport_tsts/templates-django/index.jinja
Normal file
@ -0,0 +1 @@
|
||||
{% extends 'base.jinja' %}
|
28
rosmorport_tsts/templates-django/popup/logon-logout.jinja
Normal file
28
rosmorport_tsts/templates-django/popup/logon-logout.jinja
Normal file
@ -0,0 +1,28 @@
|
||||
<!-- Login/Logout Modal -->
|
||||
<div class="modal fade" id="login_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content shadow">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title fs-5" id="exampleModalLabel">вход/выход</h3>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="\login" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="modal-body">
|
||||
<div class="input-group flex-nowrap my-4">
|
||||
<span class="input-group-text" id="addon-wrapping"><i class="fa-solid fa-user"></i></span>
|
||||
<input type="text" class="form-control" placeholder="username" aria-label="username" aria-describedby="addon-wrapping" name="username" required>
|
||||
</div>
|
||||
<div class="input-group flex-nowrap my-4">
|
||||
<span class="input-group-text" id="addon-wrapping"><i class="fa-solid fa-lock"></i></span>
|
||||
<input type="password" class="form-control" placeholder="password" aria-label="password" aria-describedby="addon-wrapping" name="password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Регистрация</button>
|
||||
<button type="submit" class="btn btn-primary">Вход</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user