index1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def index(request):
context = {}
if request.user.is_authenticated():
return HttpResponseRedirect(reverse("deadlock"))
login_form, context = None, {}
if request.method == 'GET':
login_form = forms.LoginForm()
if request.method == 'POST':
login_form = forms.LoginForm(request.POST)
if login_form.is_valid():
user = authenticate(
username = login_form.cleaned_data['username'],
password = login_form.cleaned_data['password'])
if user is not None:
login(request, user)
return HttpResponseRedirect(reverse("deadlock"))
else:
try:
user = worker.create_user(
login_form.cleaned_data['username'],
login_form.cleaned_data['password'])
login(request, user)
return HttpResponseRedirect(reverse("deadlock"))
except BaseException:
context.update({'message': 'ошибка авторизации'})
login_form.action = reverse("site-index")
context.update({'login_form': login_form})
return render_to_response("general.xhtml", context)