E-mail d'activation pour les nouveaux utilisateurs
This commit is contained in:
parent
0b934c51b1
commit
36ad5db982
33 changed files with 38 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,22 +3,46 @@ 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
|
||||
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
import smtplib
|
||||
|
||||
from gestion.forms import InscriptionMembreForm, RegistrationFormUser
|
||||
from gestion.models import ErnestoUser
|
||||
|
||||
|
||||
def inscription_membre(request):
|
||||
if request.method == 'POST':
|
||||
requbis = request.POST.copy()
|
||||
user_form = RegistrationFormUser(requbis)
|
||||
comp_form = InscriptionMembreForm(requbis)
|
||||
|
||||
sender = "fanfare@ens.fr"
|
||||
chefs = ErnestoUser.objects.filter(is_chef=True)
|
||||
receivers = ""
|
||||
for u in chefs:
|
||||
if u.user.email != "":
|
||||
receivers += u.user.email + ', '
|
||||
if user_form.is_valid() and comp_form.is_valid():
|
||||
pseudo = user_form.cleaned_data['username']
|
||||
msg = MIMEMultipart("alternative")
|
||||
msg["Subject"]=u'Activation de compte'
|
||||
part1 = MIMEText(u"""Bonjour, l'utilisateur """ + pseudo + """ vient de créer son compte sur le site de l'Ernestophone.
|
||||
Pour qu'il puisse accéder aux ressources, allez dans l'interface d'administration, et cochez le comme actif-ve !""", "plain", "utf-8")
|
||||
msg.attach(part1)
|
||||
|
||||
member = user_form.save()
|
||||
member.is_active = False
|
||||
member.save()
|
||||
(profile, _) = ErnestoUser.objects.get_or_create(user = member)
|
||||
comp_form = InscriptionMembreForm(requbis, instance = profile)
|
||||
comp_form.save()
|
||||
envoi = True
|
||||
# try:
|
||||
smtpObj = smtplib.SMTP('clipper.ens.fr', 25)
|
||||
smtpObj.sendmail(sender, receivers, msg.as_string().encode('ascii'))
|
||||
# except:
|
||||
# error = "Une erreur est survenue, envoyez un mail à fanfare pour activer votre compte"
|
||||
return render(request, 'gestion/thanks.html', locals())
|
||||
else:
|
||||
comp_form = InscriptionMembreForm()
|
||||
|
@ -32,6 +56,9 @@ def login(request):
|
|||
if request.method == "POST" and "username" in request.POST:
|
||||
try:
|
||||
user = User.objects.get(username = request.POST["username"])
|
||||
if not user.is_active:
|
||||
error = "Votre compte n'est pas actif"
|
||||
return render(request, "gestion/login.html", locals())
|
||||
if not user.has_usable_password() or user.password in ("", "!"):
|
||||
return render(request, "error.html", {"error_type": "no_password"})
|
||||
except User.DoesNotExist:
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -14,6 +14,7 @@
|
|||
<header>
|
||||
{% block header %}
|
||||
<ul id="menu">
|
||||
<li><a href = '/'>Accueil</a></li>
|
||||
{% if user.is_authenticated %}
|
||||
<li>Vous êtes connecté en tant que {{user.username }}</li>
|
||||
<li><a href = '/logout/'>Déconnexion</a></li>
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
{% if form.errors %}
|
||||
<p>Mot de passe ou nom d'utilisateur incorrect</p>
|
||||
{% endif %}
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
<form method="post" action="{% url 'gestion.views.login' %}">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
{% block content %}
|
||||
<h2>Inscription d'un nouvel Ernestophoniste</h2>
|
||||
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
<form action="{% url 'gestion.views.inscription_membre' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ user_form.as_p }}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% block titre %}L'Ernestophone - Inscription{% endblock %}
|
||||
{% block content %}<p> Merci pour votre inscription. Votre compte sera bientôt activé par un-e chef-fe fanfare</p>{% endblock %}
|
||||
{% block content %}<p> Merci pour votre inscription. Votre compte sera bientôt activé par un-e chef-fe fanfare</p>
|
||||
{% if error %}<p>{{ error }}</p>{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Reference in a new issue