Commit f4ce6b0b authored by Amap's avatar Amap

Possibilité pour les non-loggé de créer un compte.

parent 9f6d2711
......@@ -8,9 +8,16 @@ from .models import User, get_admin_right
class PassForm(forms.Form):
passwd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=255, widget=forms.PasswordInput)
passwd2 = forms.CharField(label=u'Saisir à nouveau le mot de passe', max_length=255, widget=forms.PasswordInput)
passwd1 = forms.CharField(label=u'Nouveau mot de passe', min_length=8, max_length=255, widget=forms.PasswordInput)
passwd2 = forms.CharField(label=u'Saisir à nouveau le mot de passe', min_length=8, max_length=255, widget=forms.PasswordInput)
def clean_passwd2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get("passwd1")
password2 = self.cleaned_data.get("passwd2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2
class UserCreationForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
......
{% extends "users/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modification d'utilisateur{% endblock %}
{% block content %}
{% bootstrap_form_errors userform %}
{% bootstrap_form_errors userpass %}
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form userform %}
{% bootstrap_form userpass %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br />
<br />
<br />
{% endblock %}
......@@ -39,9 +39,6 @@ def form(ctx, template, request):
def password_change_action(u_form, user, request, req=False):
""" Fonction qui effectue le changeemnt de mdp bdd"""
if u_form.cleaned_data['passwd1'] != u_form.cleaned_data['passwd2']:
messages.error(request, "Les 2 mots de passe différent")
return form({'userform': u_form}, 'users/user.html', request)
user.set_password(u_form.cleaned_data['passwd1'])
with transaction.atomic(), reversion.create_revision():
user.save()
......@@ -68,24 +65,17 @@ def reset_passwd_mail(req, request):
EMAIL_FROM, [req.user.email], fail_silently=False)
return
@login_required
@permission_required('bureau')
def new_user(request):
user = EditInfoForm(request.POST or None)
if user.is_valid():
userpass = PassForm(request.POST or None)
if user.is_valid() and userpass.is_valid():
user = user.save(commit=False)
with transaction.atomic(), reversion.create_revision():
user.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
req = Request()
req.type = Request.PASSWD
req.user = user
req.save()
reset_passwd_mail(req, request)
messages.success(request, u"L'utilisateur %s a été crée, un mail pour l'initialisation du mot de passe a été envoyé" % user.pseudo)
user.set_password(userpass.cleaned_data["passwd1"])
return redirect("/users/profil/" + str(user.id))
return form({'userform': user}, 'users/user.html', request)
return form({'userform': user, 'userpass':userpass}, 'users/new_user.html', request)
@login_required
def edit_info(request, userid):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment