Améliore le formulaire de mdp K-Fêt

This commit is contained in:
Ludovic Stephan 2021-02-20 15:44:44 +01:00
parent 209360f535
commit aac94afcd0
2 changed files with 31 additions and 18 deletions

View file

@ -90,21 +90,34 @@ class AccountPwdForm(forms.Form):
label="Mot de passe K-Fêt", label="Mot de passe K-Fêt",
required=False, required=False,
help_text="Le mot de passe doit contenir au moins huit caractères", help_text="Le mot de passe doit contenir au moins huit caractères",
widget=forms.PasswordInput, widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}),
min_length=8,
) )
pwd2 = forms.CharField( pwd2 = forms.CharField(
label="Confirmer le mot de passe", required=False, widget=forms.PasswordInput label="Confirmer le mot de passe",
required=False,
widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}),
) )
def __init__(self, *args, account=None, **kwargs):
super().__init__(*args, **kwargs)
self.account = account
def clean(self): def clean(self):
pwd1 = self.cleaned_data.get("pwd1", "") pwd1 = self.cleaned_data.get("pwd1", "")
pwd2 = self.cleaned_data.get("pwd2", "") pwd2 = self.cleaned_data.get("pwd2", "")
if len(pwd1) < 8:
raise ValidationError("Mot de passe trop court")
if pwd1 != pwd2: if pwd1 != pwd2:
raise ValidationError("Les mots de passes sont différents") self.add_error("pwd2", "Les mots de passe doivent être identiques !")
super().clean() super().clean()
def save(self, commit=True):
password = self.cleaned_data["pwd1"]
self.account.set_password(password)
if commit:
self.account.save()
return self.account
class CofForm(forms.ModelForm): class CofForm(forms.ModelForm):
def clean_is_cof(self): def clean_is_cof(self):

View file

@ -6,29 +6,29 @@
{% block title %} {% block title %}
{% if account.user == request.user %} {% if account.user == request.user %}
Modification de mes informations Modification de mes informations
{% else %} {% else %}
{{ account.trigramme }} - Édition {{ account.trigramme }} - Édition
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block header-title %} {% block header-title %}
{% if account.user == request.user %} {% if account.user == request.user %}
Modification de mes informations Modification de mes informations
{% else %} {% else %}
Édition du compte {{ account.trigramme }} Édition du compte {{ account.trigramme }}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
{% if not account.is_team %} {% if not account.is_team %}
{% include "kfet/base_footer.html" %} {% include "kfet/base_footer.html" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block main %} {% block main %}
<form action="" method="post" class="form-horizontal"> <form action="" method="post" class="form-horizontal" autocomplete="off">
{% csrf_token %} {% csrf_token %}
{% include 'kfet/form_snippet.html' with form=user_info_form %} {% include 'kfet/form_snippet.html' with form=user_info_form %}
{% include 'kfet/form_snippet.html' with form=account_form %} {% include 'kfet/form_snippet.html' with form=account_form %}
@ -43,13 +43,13 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function () {
$('#id_authz_overdraft_until').datetimepicker({ $('#id_authz_overdraft_until').datetimepicker({
format: 'YYYY-MM-DD HH:mm', format: 'YYYY-MM-DD HH:mm',
stepping: 5, stepping: 5,
locale: 'fr', locale: 'fr',
}); });
}); });
</script> </script>