mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 03:43:12 +00:00
Vue pour mot de passe oublié
This commit is contained in:
parent
4674594f9a
commit
f4cfc6f571
5 changed files with 28 additions and 8 deletions
|
@ -19,14 +19,12 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
|
<p><form method="post" action="{% url 'django.contrib.auth.views.login' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
{% bootstrap_button "Login" button_type="submit" icon="log-in" %}
|
{% bootstrap_button "Login" button_type="submit" icon="log-in" %}
|
||||||
<input type="hidden" name="next" value="{{ next }}" />
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
</form>
|
</form></p>
|
||||||
|
<p><a class="btn btn-warning btn-sm" role="button" href="{% url 'users:reset-password' %}"> Mot de passe oublié ?</a></p>
|
||||||
{# Assumes you setup the password_reset view in your URLconf #}
|
|
||||||
{# <p><a href="{% url 'password_reset' %}">Lost password?</a></p> #}
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -70,3 +70,7 @@ class UserChangeForm(forms.ModelForm):
|
||||||
if commit:
|
if commit:
|
||||||
user.save()
|
user.save()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
class ResetPasswordForm(forms.Form):
|
||||||
|
pseudo = forms.CharField(label=u'Pseudo', max_length=255)
|
||||||
|
email = forms.EmailField(max_length=255)
|
||||||
|
|
|
@ -322,7 +322,6 @@ class UserForm(InfoForm):
|
||||||
class Meta(InfoForm.Meta):
|
class Meta(InfoForm.Meta):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
class PasswordForm(ModelForm):
|
class PasswordForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
|
|
|
@ -22,6 +22,7 @@ urlpatterns = [
|
||||||
url(r'^index_school/$', views.index_school, name='index-school'),
|
url(r'^index_school/$', views.index_school, name='index-school'),
|
||||||
url(r'^mon_profil/$', views.mon_profil, name='mon-profil'),
|
url(r'^mon_profil/$', views.mon_profil, name='mon-profil'),
|
||||||
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
|
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
|
||||||
|
url(r'^reset_password/$', views.reset_password, name='reset-password'),
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm
|
||||||
from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm
|
from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from machines.models import Machine, Interface
|
from machines.models import Machine, Interface
|
||||||
from users.forms import PassForm
|
from users.forms import PassForm, ResetPasswordForm
|
||||||
from machines.views import unassign_ips, assign_ips
|
from machines.views import unassign_ips, assign_ips
|
||||||
|
|
||||||
from re2o.login import hashNT
|
from re2o.login import hashNT
|
||||||
|
@ -352,6 +352,23 @@ def profil(request, userid):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def reset_password(request):
|
||||||
|
userform = ResetPasswordForm(request.POST or None)
|
||||||
|
if userform.is_valid():
|
||||||
|
try:
|
||||||
|
user = User.objects.get(pseudo=userform.cleaned_data['pseudo'],email=userform.cleaned_data['email'])
|
||||||
|
except User.DoesNotExist:
|
||||||
|
messages.error(request, "Cet utilisateur n'existe pas")
|
||||||
|
return form({'userform': userform}, 'users/user.html', request)
|
||||||
|
req = Request()
|
||||||
|
req.type = Request.PASSWD
|
||||||
|
req.user = user
|
||||||
|
req.save()
|
||||||
|
reset_passwd_mail(req, request)
|
||||||
|
messages.success(request, "Un mail pour l'initialisation du mot de passe a été envoyé")
|
||||||
|
redirect("/")
|
||||||
|
return form({'userform': userform}, 'users/user.html', request)
|
||||||
|
|
||||||
def process(request, token):
|
def process(request, token):
|
||||||
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
||||||
req = get_object_or_404(valid_reqs, token=token)
|
req = get_object_or_404(valid_reqs, token=token)
|
||||||
|
@ -361,7 +378,8 @@ def process(request, token):
|
||||||
elif req.type == Request.EMAIL:
|
elif req.type == Request.EMAIL:
|
||||||
return process_email(request, req=req)
|
return process_email(request, req=req)
|
||||||
else:
|
else:
|
||||||
return error(request, 'Entrée incorrecte, contactez un admin')
|
messages.error(request, "Entrée incorrecte, contactez un admin")
|
||||||
|
redirect("/")
|
||||||
|
|
||||||
def process_passwd(request, req):
|
def process_passwd(request, req):
|
||||||
u_form = PassForm(request.POST or None)
|
u_form = PassForm(request.POST or None)
|
||||||
|
|
Loading…
Reference in a new issue