2015-03-17 19:03:51 +01:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.contrib.auth.views import login as django_login_view
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.auth.forms import AuthenticationForm
|
|
|
|
|
2015-03-19 18:51:11 +01:00
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
|
|
|
|
import smtplib
|
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
from gestion.forms import InscriptionMembreForm, RegistrationFormUser
|
|
|
|
from gestion.models import ErnestoUser
|
|
|
|
|
2015-03-19 18:51:11 +01:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
def inscription_membre(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
requbis = request.POST.copy()
|
|
|
|
user_form = RegistrationFormUser(requbis)
|
|
|
|
comp_form = InscriptionMembreForm(requbis)
|
|
|
|
if user_form.is_valid() and comp_form.is_valid():
|
|
|
|
pseudo = user_form.cleaned_data['username']
|
2015-03-28 19:18:14 +01:00
|
|
|
if not (comp_form.cleaned_data['validation'] == "Pouet-ta-mere"):
|
|
|
|
error = "Le champ Validation ne correspond pas à celui attendu"
|
|
|
|
return render(request, "gestion/registration.html", locals())
|
2015-03-17 19:03:51 +01:00
|
|
|
member = user_form.save()
|
2015-03-19 18:51:11 +01:00
|
|
|
member.save()
|
2015-03-17 19:03:51 +01:00
|
|
|
(profile, _) = ErnestoUser.objects.get_or_create(user = member)
|
|
|
|
comp_form = InscriptionMembreForm(requbis, instance = profile)
|
|
|
|
comp_form.save()
|
|
|
|
envoi = True
|
|
|
|
return render(request, 'gestion/thanks.html', locals())
|
|
|
|
else:
|
|
|
|
comp_form = InscriptionMembreForm()
|
|
|
|
user_form = RegistrationFormUser()
|
|
|
|
return render(request, 'gestion/registration.html', locals())
|
|
|
|
|
|
|
|
def home(request):
|
|
|
|
return render(request, 'gestion/home.html', {} )
|
|
|
|
|
|
|
|
def login(request):
|
|
|
|
if request.method == "POST" and "username" in request.POST:
|
|
|
|
try:
|
|
|
|
user = User.objects.get(username = request.POST["username"])
|
2015-03-19 18:51:11 +01:00
|
|
|
if not user.is_active:
|
|
|
|
error = "Votre compte n'est pas actif"
|
|
|
|
return render(request, "gestion/login.html", locals())
|
2015-03-17 19:03:51 +01:00
|
|
|
if not user.has_usable_password() or user.password in ("", "!"):
|
|
|
|
return render(request, "error.html", {"error_type": "no_password"})
|
|
|
|
except User.DoesNotExist:
|
|
|
|
pass
|
|
|
|
return django_login_view(request, template_name = 'login.html', )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|