2015-11-19 08:46:05 +00:00
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
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):
|
2015-11-19 08:46:05 +00:00
|
|
|
return render(request, "core/index.html", {'title': 'Bienvenue!'})
|
2015-11-18 08:44:06 +00:00
|
|
|
|
|
|
|
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')
|
2015-11-19 08:46:05 +00:00
|
|
|
|
|
|
|
def user(request, user_id=None):
|
|
|
|
if user_id == None:
|
|
|
|
return render(request, "core/user.html", {'user_list': User.objects.all})
|
|
|
|
user = get_object_or_404(User, pk=user_id)
|
|
|
|
return render(request, "core/user.html", {'profile': user})
|
|
|
|
|
|
|
|
def user_edit(request, user_id):
|
|
|
|
pass
|
|
|
|
|