Browse Source

Создана основа аутентификации пользователя #17

pull/32/head
Artur Galyamov 2 years ago
parent
commit
34259d5977
  1. 9
      cms/forms.py
  2. 26
      cms/templates/user/sign_in.html
  3. 7
      cms/urls.py
  4. 17
      cms/views.py
  5. 2
      crossposting_backend/urls.py
  6. 8
      crossposting_backend/views.py

9
cms/forms.py

@ -1,4 +1,5 @@
from django import forms
from django.contrib.auth import models as auth_models
from .models import Article
@ -7,3 +8,11 @@ class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ('body', 'link',)
class UserForm(forms.ModelForm):
password = forms.PasswordInput()
class Meta:
model = auth_models.User
fields = ('username', 'password',)

26
cms/templates/user/sign_in.html

@ -0,0 +1,26 @@
{% extends 'base.html' %}
{% load bootstrap5 %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-12">
<form
action="{% url 'authenticate' %}"
method="post"
enctype="application/x-www-form-urlencoded"
>
{% csrf_token %}
{% bootstrap_form user_form %}
{% buttons %}
<button
class="btn btn-primary"
type="submit"
>
Войти
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>
{% endblock %}

7
cms/urls.py

@ -1,8 +1,13 @@
from django.urls import path
from .views import ArticleView, new_article
from .views import ArticleView, new_article, AuthenticationView
urlpatterns = [
path('articles/', ArticleView.as_view(), name='create-article'),
path('articles/new/', new_article, name='new-article'),
path(
'',
AuthenticationView.as_view(),
name='authenticate'
)
]

17
cms/views.py

@ -3,10 +3,13 @@ from json import JSONEncoder
import requests
from django.http import HttpRequest
from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from django.views import View as BaseView
from cms.forms import ArticleForm
from cms.forms import UserForm
from cms.models import Article
@ -86,3 +89,17 @@ def new_article(request):
return render(request,
template_name='articles/new.html',
context=article_context)
class AuthenticationView(BaseView):
def get(self, request, *args, **kwargs):
user_form = UserForm()
auth_context = {
'user_form': user_form,
}
return render(request,
'user/sign_in.html',
context=auth_context)
def post(self, request, *args, **kwargs):
return HttpResponse('ok')

2
crossposting_backend/urls.py

@ -15,8 +15,10 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from .views import handle_root_path
urlpatterns = [
path('admin/', admin.site.urls),
path('cms/', include('cms.urls')),
path('', handle_root_path, name='root'),
]

8
crossposting_backend/views.py

@ -0,0 +1,8 @@
from django.http import HttpResponseRedirect
from django.urls import reverse
def handle_root_path(request):
return HttpResponseRedirect(reverse('authenticate'))
Loading…
Cancel
Save