summaryrefslogtreecommitdiff
path: root/forums/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'forums/views.py')
-rw-r--r--forums/views.py38
1 files changed, 17 insertions, 21 deletions
diff --git a/forums/views.py b/forums/views.py
index a38d6b7..b2dae90 100644
--- a/forums/views.py
+++ b/forums/views.py
@@ -8,29 +8,25 @@ from forums.forms import UserLoginForm
def user_login(request):
if request.user.is_anonymous():
if request.method == 'POST':
- username = request.POST['username']
- password = request.POST['password']
- user = authenticate(username=username, password=password)
- if user is not None:
- if user.is_active:
- login(request, user)
- if 'next' in request.POST:
- next_url = request.POST.get('next')
- return HttpResponseRedirect(next_url)
- return HttpResponseRedirect('/')
- else:
- return HttpResponse('you are blocked')
- else:
- return HttpResponse('Invalid username or password')
+ form = UserLoginForm(request.POST)
+ if form.is_valid():
+ cleaned_data = form.cleaned_data
+ user = cleaned_data.get("user")
+ login(request, user)
+ if 'next' in request.POST:
+ next_url = request.POST.get('next')
+ return HttpResponseRedirect(next_url)
+ return HttpResponseRedirect('/')
else:
form = UserLoginForm()
- next_url = request.GET.get('next')
- context = {
- 'form': form,
- 'next': next_url
- }
- context.update(csrf(request))
- return render_to_response('forums/templates/user-login.html', context)
+
+ next_url = request.GET.get('next')
+ context = {
+ 'form': form,
+ 'next': next_url
+ }
+ context.update(csrf(request))
+ return render_to_response('forums/templates/user-login.html', context)
else:
return HttpResponseRedirect('/')