diff options
Diffstat (limited to 'forums/views.py')
-rw-r--r-- | forums/views.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/forums/views.py b/forums/views.py new file mode 100644 index 0000000..6890d61 --- /dev/null +++ b/forums/views.py @@ -0,0 +1,34 @@ +from django.http import HttpResponse, HttpResponseRedirect +from django.contrib.auth import login, logout, authenticate +from django.shortcuts import render_to_response +from django.core.context_processors import csrf + +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) + return HttpResponseRedirect('/') + else: + return HttpResponse('you are blocked') + else: + return HttpResponse('Invalid username or password') + else: + form = UserLoginForm() + context = { + 'form': form + } + context.update(csrf(request)) + return render_to_response('forums/templates/user-login.html', context) + else: + return HttpResponseRedirect('/') + +def user_logout(request): + logout(request) + return HttpResponseRedirect('/') |