2015-11-18 16:09:06 +00:00
|
|
|
from django.shortcuts import render, redirect
|
2015-11-18 08:44:06 +00:00
|
|
|
from django.http import HttpResponse
|
2015-11-18 16:09:06 +00:00
|
|
|
from django.contrib.auth import logout as auth_logout
|
2015-11-18 08:44:06 +00:00
|
|
|
|
|
|
|
from .models import User
|
2015-11-18 16:09:06 +00:00
|
|
|
from .forms import RegisteringForm, LoginForm
|
2015-11-18 08:44:06 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
return HttpResponse("Hello, world. You're at the core index.")
|
|
|
|
|
|
|
|
def register(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = RegisteringForm(request.POST)
|
|
|
|
if form.is_valid():
|
2015-11-18 16:09:06 +00:00
|
|
|
logging.debug("Registering "+form.cleaned_data['first_name']+form.cleaned_data['last_name'])
|
|
|
|
u = form.save()
|
|
|
|
form = RegisteringForm()
|
|
|
|
else:
|
|
|
|
form = RegisteringForm()
|
|
|
|
return render(request, "core/register.html", {'title': 'Register a user', 'form': form.as_p()})
|
|
|
|
|
|
|
|
def login(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
try:
|
|
|
|
form = LoginForm(request)
|
|
|
|
form.login()
|
|
|
|
# TODO redirect to profile when done
|
|
|
|
return redirect('index')
|
|
|
|
except Exception as e:
|
|
|
|
logging.debug(e)
|
|
|
|
else:
|
|
|
|
form = LoginForm()
|
|
|
|
return render(request, "core/login.html", {'title': 'Login', 'form': form.as_p()})
|
2015-11-18 08:44:06 +00:00
|
|
|
|
2015-11-18 16:09:06 +00:00
|
|
|
def logout(request):
|
|
|
|
auth_logout(request)
|
|
|
|
return redirect('core:index')
|