1
from django.shortcuts import render
2
from django.contrib import auth
3
from django.http import HttpResponseRedirect
4
from django.urls import reverse
5
from django.contrib.auth.decorators import login_required
6
from authapp.forms import AuthUserRegisterForm, AuthUserLoginForm, AuthUserEditForm
10
login_form = AuthUserLoginForm(data=request.POST)
11
if 'next' in request.GET.keys():
12
next_value = request.GET['next']
15
if request.method == 'POST' and login_form.is_valid():
16
username = request.POST.get('username')
17
password = request.POST.get('password')
19
user = auth.authenticate(username=username, password=password)
21
auth.login(request, user)
22
if 'next' in request.POST.keys():
23
return HttpResponseRedirect(request.POST['next'])
25
return HttpResponseRedirect(reverse('home'))
28
'login_form': login_form,
31
return render(request, 'authapp/login.html', context)
36
return HttpResponseRedirect(reverse('auth:login'))
40
if request.method == 'POST':
41
register_form = AuthUserRegisterForm(request.POST, request.FILES)
43
if register_form.is_valid():
45
return HttpResponseRedirect(reverse('home'))
47
register_form = AuthUserRegisterForm()
50
'title': 'Регистрация',
51
'register_form': register_form,
53
return render(request, 'authapp/register.html', context)
58
if request.method == 'POST':
59
edit_form = AuthUserEditForm(request.POST, request.FILES, instance=request.user)
60
if edit_form.is_valid():
62
return HttpResponseRedirect(reverse('home'))
64
edit_form = AuthUserEditForm(instance=request.user)
68
'edit_form': edit_form,
70
return render(request, 'authapp/edit.html', context)