2016-06-30 18:18:06 +00:00
|
|
|
# App de gestion des users pour re2o
|
|
|
|
# Goulven Kermarec, Gabriel Détraz
|
|
|
|
# Gplv2
|
2016-07-20 01:53:46 +00:00
|
|
|
from django.shortcuts import render_to_response, get_object_or_404, render, redirect
|
2016-06-30 18:18:06 +00:00
|
|
|
from django.core.context_processors import csrf
|
2016-07-20 01:53:46 +00:00
|
|
|
from django.template import Context, RequestContext, loader
|
2016-07-01 20:47:08 +00:00
|
|
|
from django.contrib import messages
|
2016-07-09 02:12:09 +00:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2016-07-06 17:45:36 +00:00
|
|
|
from django.db.models import Max, ProtectedError
|
2016-07-04 20:37:04 +00:00
|
|
|
from django.db import IntegrityError
|
2016-07-20 01:53:46 +00:00
|
|
|
from django.core.mail import send_mail
|
2016-07-03 00:15:17 +00:00
|
|
|
from django.utils import timezone
|
2016-07-20 01:53:46 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2016-06-30 01:39:07 +00:00
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
from users.models import User, Right, Ban, Whitelist, School, Request
|
2016-07-08 01:12:28 +00:00
|
|
|
from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm
|
2016-07-09 17:51:37 +00:00
|
|
|
from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm
|
2016-07-03 16:09:58 +00:00
|
|
|
from cotisations.models import Facture
|
2016-07-04 01:01:09 +00:00
|
|
|
from machines.models import Machine, Interface
|
2016-07-20 10:06:33 +00:00
|
|
|
from users.forms import PassForm, ResetPasswordForm
|
2016-07-04 15:13:26 +00:00
|
|
|
from machines.views import unassign_ips, assign_ips
|
2016-06-30 18:18:06 +00:00
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
from re2o.login import hashNT
|
2016-07-20 01:53:46 +00:00
|
|
|
from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME
|
2016-07-01 22:35:44 +00:00
|
|
|
|
2016-07-04 09:31:20 +00:00
|
|
|
def archive(user):
|
|
|
|
""" Archive un utilisateur """
|
|
|
|
unassign_ips(user)
|
|
|
|
return
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-04 15:13:26 +00:00
|
|
|
def unarchive(user):
|
|
|
|
""" Triger actions au desarchivage d'un user """
|
|
|
|
assign_ips(user)
|
|
|
|
return
|
|
|
|
|
2016-06-30 18:18:06 +00:00
|
|
|
def form(ctx, template, request):
|
|
|
|
c = ctx
|
|
|
|
c.update(csrf(request))
|
2016-07-08 01:12:28 +00:00
|
|
|
return render_to_response(
|
|
|
|
template,
|
|
|
|
c,
|
|
|
|
context_instance=RequestContext(request)
|
|
|
|
)
|
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
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'])
|
|
|
|
user.pwd_ntlm = hashNT(u_form.cleaned_data['passwd1'])
|
|
|
|
user.save()
|
|
|
|
messages.success(request, "Le mot de passe a changé")
|
|
|
|
if req:
|
|
|
|
req.delete()
|
|
|
|
return redirect("/")
|
|
|
|
return redirect("/users/profil/" + str(user.id))
|
|
|
|
|
|
|
|
def reset_passwd_mail(req, request):
|
|
|
|
t = loader.get_template('users/email_passwd_request')
|
|
|
|
c = Context({
|
|
|
|
'name': str(req.user.name) + ' ' + str(req.user.surname),
|
|
|
|
'asso': ASSO_NAME,
|
|
|
|
'asso_mail': ASSO_EMAIL,
|
|
|
|
'site_name': SITE_NAME,
|
|
|
|
'url': request.build_absolute_uri(
|
|
|
|
reverse('users:process', kwargs={'token': req.token})),
|
|
|
|
'expire_in': REQ_EXPIRE_STR,
|
|
|
|
})
|
|
|
|
send_mail('Changement de mot de passe', t.render(c),
|
|
|
|
EMAIL_FROM, [req.user.email], fail_silently=False)
|
|
|
|
return
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-06-30 18:18:06 +00:00
|
|
|
def new_user(request):
|
2016-07-02 00:42:04 +00:00
|
|
|
user = InfoForm(request.POST or None)
|
|
|
|
if user.is_valid():
|
2016-07-20 01:53:46 +00:00
|
|
|
user = user.save(commit=False)
|
2016-07-02 00:42:04 +00:00
|
|
|
user.save()
|
2016-07-20 01:53:46 +00:00
|
|
|
req = Request()
|
|
|
|
req.type = Request.PASSWD
|
|
|
|
req.user = user
|
|
|
|
req.save()
|
|
|
|
reset_passwd_mail(req, request)
|
|
|
|
messages.success(request, "L'utilisateur %s a été crée, un mail pour l'initialisation du mot de passe a été envoyé" % user.pseudo)
|
|
|
|
redirect("/users/profil/" + user.id)
|
2016-07-02 00:42:04 +00:00
|
|
|
return form({'userform': user}, 'users/user.html', request)
|
2016-07-01 16:22:52 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-01 16:22:52 +00:00
|
|
|
def edit_info(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-01 20:47:08 +00:00
|
|
|
return redirect("/users/")
|
2016-07-11 21:49:08 +00:00
|
|
|
if not request.user.has_perms(('cableur',)) and user != request.user:
|
|
|
|
messages.error(request, "Vous ne pouvez pas modifier un autre user que vous sans droit cableur")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
2016-07-09 17:51:37 +00:00
|
|
|
if not request.user.has_perms(('cableur',)):
|
|
|
|
user = BaseInfoForm(request.POST or None, instance=user)
|
|
|
|
else:
|
|
|
|
user = InfoForm(request.POST or None, instance=user)
|
2016-07-01 16:22:52 +00:00
|
|
|
if user.is_valid():
|
|
|
|
user.save()
|
2016-07-02 00:42:04 +00:00
|
|
|
messages.success(request, "L'user a bien été modifié")
|
2016-07-06 22:25:12 +00:00
|
|
|
return redirect("/users/profil/" + userid)
|
2016-07-01 16:22:52 +00:00
|
|
|
return form({'userform': user}, 'users/user.html', request)
|
2016-07-01 20:47:08 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('bureau')
|
2016-07-01 20:47:08 +00:00
|
|
|
def state(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-01 20:47:08 +00:00
|
|
|
return redirect("/users/")
|
2016-07-04 09:31:20 +00:00
|
|
|
state = StateForm(request.POST or None, instance=user)
|
|
|
|
if state.is_valid():
|
|
|
|
if state.has_changed():
|
|
|
|
if state.cleaned_data['state'] == User.STATE_ARCHIVED:
|
|
|
|
archive(user)
|
2016-07-04 15:13:26 +00:00
|
|
|
else:
|
|
|
|
unarchive(user)
|
2016-07-04 09:31:20 +00:00
|
|
|
state.save()
|
2016-07-02 00:42:04 +00:00
|
|
|
messages.success(request, "Etat changé avec succès")
|
2016-07-06 22:25:12 +00:00
|
|
|
return redirect("/users/profil/" + userid)
|
2016-07-04 09:31:20 +00:00
|
|
|
return form({'userform': state}, 'users/user.html', request)
|
2016-07-01 20:47:08 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-01 20:47:08 +00:00
|
|
|
def password(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-01 20:47:08 +00:00
|
|
|
return redirect("/users/")
|
2016-07-11 21:49:08 +00:00
|
|
|
if not request.user.has_perms(('cableur',)) and user != request.user:
|
|
|
|
messages.error(request, "Vous ne pouvez pas modifier un autre user que vous sans droit cableur")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
|
|
|
if not request.user.has_perms(('bureau',)) and user != request.user and Right.objects.filter(user=user):
|
2016-07-09 16:26:39 +00:00
|
|
|
messages.error(request, "Il faut les droits bureau pour modifier le mot de passe d'un membre actif")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
2016-07-08 01:12:28 +00:00
|
|
|
u_form = PassForm(request.POST or None)
|
|
|
|
if u_form.is_valid():
|
2016-07-20 01:53:46 +00:00
|
|
|
return password_change_action(u_form, user, request)
|
2016-07-08 01:12:28 +00:00
|
|
|
return form({'userform': u_form}, 'users/user.html', request)
|
2016-07-01 22:35:44 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('bureau')
|
2016-07-04 20:37:04 +00:00
|
|
|
def add_right(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-04 20:37:04 +00:00
|
|
|
return redirect("/users/")
|
2016-07-02 00:07:17 +00:00
|
|
|
right = RightForm(request.POST or None)
|
|
|
|
if right.is_valid():
|
2016-07-04 20:37:04 +00:00
|
|
|
right = right.save(commit=False)
|
|
|
|
right.user = user
|
|
|
|
try:
|
|
|
|
right.save()
|
|
|
|
messages.success(request, "Droit ajouté")
|
|
|
|
except IntegrityError:
|
|
|
|
pass
|
2016-07-06 22:25:12 +00:00
|
|
|
return redirect("/users/profil/" + userid)
|
2016-07-02 00:07:17 +00:00
|
|
|
return form({'userform': right}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('bureau')
|
2016-07-02 02:40:24 +00:00
|
|
|
def del_right(request):
|
|
|
|
right = DelRightForm(request.POST or None)
|
|
|
|
if right.is_valid():
|
|
|
|
right_del = right.cleaned_data['rights']
|
|
|
|
right_del.delete()
|
|
|
|
messages.success(request, "Droit retiré avec succès")
|
|
|
|
return redirect("/users/")
|
|
|
|
return form({'userform': right}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('bofh')
|
2016-07-02 20:31:50 +00:00
|
|
|
def add_ban(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-02 20:31:50 +00:00
|
|
|
return redirect("/users/")
|
|
|
|
ban_instance = Ban(user=user)
|
|
|
|
ban = BanForm(request.POST or None, instance=ban_instance)
|
|
|
|
if ban.is_valid():
|
|
|
|
ban.save()
|
|
|
|
messages.success(request, "Bannissement ajouté")
|
2016-07-06 22:25:12 +00:00
|
|
|
return redirect("/users/profil/" + userid)
|
2016-07-10 14:39:21 +00:00
|
|
|
if user.is_ban():
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
|
|
|
"Attention, cet utilisateur a deja un bannissement actif"
|
|
|
|
)
|
2016-07-02 20:31:50 +00:00
|
|
|
return form({'userform': ban}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('bofh')
|
2016-07-02 20:31:50 +00:00
|
|
|
def edit_ban(request, banid):
|
|
|
|
try:
|
|
|
|
ban_instance = Ban.objects.get(pk=banid)
|
2016-07-04 18:04:11 +00:00
|
|
|
except Ban.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Entrée inexistante")
|
2016-07-02 20:31:50 +00:00
|
|
|
return redirect("/users/")
|
|
|
|
ban = BanForm(request.POST or None, instance=ban_instance)
|
|
|
|
if ban.is_valid():
|
|
|
|
ban.save()
|
|
|
|
messages.success(request, "Bannissement modifié")
|
|
|
|
return redirect("/users/")
|
|
|
|
return form({'userform': ban}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-04 18:04:11 +00:00
|
|
|
def add_whitelist(request, userid):
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-04 18:04:11 +00:00
|
|
|
return redirect("/users/")
|
|
|
|
whitelist_instance = Whitelist(user=user)
|
|
|
|
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
|
|
|
|
if whitelist.is_valid():
|
|
|
|
whitelist.save()
|
|
|
|
messages.success(request, "Accès à titre gracieux accordé")
|
2016-07-06 22:25:12 +00:00
|
|
|
return redirect("/users/profil/" + userid)
|
2016-07-04 18:04:11 +00:00
|
|
|
if is_whitelisted(user):
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
|
|
|
"Attention, cet utilisateur a deja un accès gracieux actif"
|
|
|
|
)
|
2016-07-04 18:04:11 +00:00
|
|
|
return form({'userform': whitelist}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-04 18:04:11 +00:00
|
|
|
def edit_whitelist(request, whitelistid):
|
|
|
|
try:
|
|
|
|
whitelist_instance = Whitelist.objects.get(pk=whitelistid)
|
|
|
|
except Whitelist.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Entrée inexistante")
|
2016-07-04 18:04:11 +00:00
|
|
|
return redirect("/users/")
|
|
|
|
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
|
|
|
|
if whitelist.is_valid():
|
|
|
|
whitelist.save()
|
|
|
|
messages.success(request, "Whitelist modifiée")
|
|
|
|
return redirect("/users/")
|
|
|
|
return form({'userform': whitelist}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-06 17:45:36 +00:00
|
|
|
def add_school(request):
|
|
|
|
school = SchoolForm(request.POST or None)
|
|
|
|
if school.is_valid():
|
|
|
|
school.save()
|
|
|
|
messages.success(request, "L'établissement a été ajouté")
|
2016-07-08 00:25:12 +00:00
|
|
|
return redirect("/users/index_school/")
|
2016-07-08 01:12:28 +00:00
|
|
|
return form({'userform': school}, 'users/user.html', request)
|
2016-07-06 17:45:36 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-08 00:25:12 +00:00
|
|
|
def edit_school(request, schoolid):
|
|
|
|
try:
|
|
|
|
school_instance = School.objects.get(pk=schoolid)
|
|
|
|
except School.DoesNotExist:
|
|
|
|
messages.error(request, u"Entrée inexistante" )
|
|
|
|
return redirect("/users/")
|
|
|
|
school = SchoolForm(request.POST or None, instance=school_instance)
|
|
|
|
if school.is_valid():
|
|
|
|
school.save()
|
|
|
|
messages.success(request, "Établissement modifié")
|
|
|
|
return redirect("/users/index_school/")
|
|
|
|
return form({'userform': school}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-06 17:45:36 +00:00
|
|
|
def del_school(request):
|
|
|
|
school = DelSchoolForm(request.POST or None)
|
|
|
|
if school.is_valid():
|
|
|
|
school_dels = school.cleaned_data['schools']
|
|
|
|
for school_del in school_dels:
|
|
|
|
try:
|
|
|
|
school_del.delete()
|
|
|
|
messages.success(request, "L'établissement a été supprimé")
|
|
|
|
except ProtectedError:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
|
|
|
"L'établissement %s est affecté à au moins un user, \
|
2016-07-08 01:40:04 +00:00
|
|
|
vous ne pouvez pas le supprimer" % school_del)
|
2016-07-08 00:25:12 +00:00
|
|
|
return redirect("/users/index_school/")
|
2016-07-06 17:45:36 +00:00
|
|
|
return form({'userform': school}, 'users/user.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 16:26:39 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-01 22:35:44 +00:00
|
|
|
def index(request):
|
2016-07-02 00:07:17 +00:00
|
|
|
users_list = User.objects.order_by('pk')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'users/index.html', {'users_list': users_list})
|
2016-07-03 16:09:58 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-05 17:34:57 +00:00
|
|
|
def index_ban(request):
|
|
|
|
ban_list = Ban.objects.order_by('date_start')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'users/index_ban.html', {'ban_list': ban_list})
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-05 17:34:57 +00:00
|
|
|
def index_white(request):
|
|
|
|
white_list = Whitelist.objects.order_by('date_start')
|
2016-07-08 01:12:28 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
'users/index_whitelist.html',
|
|
|
|
{'white_list': white_list}
|
|
|
|
)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-08 00:25:12 +00:00
|
|
|
def index_school(request):
|
|
|
|
school_list = School.objects.order_by('name')
|
|
|
|
return render(request, 'users/index_schools.html', {'school_list':school_list})
|
|
|
|
|
2016-07-10 02:02:48 +00:00
|
|
|
@login_required
|
|
|
|
def mon_profil(request):
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-05 17:34:57 +00:00
|
|
|
def profil(request, userid):
|
|
|
|
try:
|
|
|
|
users = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(request, "Utilisateur inexistant")
|
2016-07-05 17:34:57 +00:00
|
|
|
return redirect("/users/")
|
2016-07-11 21:49:08 +00:00
|
|
|
if not request.user.has_perms(('cableur',)) and users != request.user:
|
|
|
|
messages.error(request, "Vous ne pouvez pas afficher un autre user que vous sans droit cableur")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
2016-07-18 03:30:35 +00:00
|
|
|
machines = Machine.objects.filter(user__pseudo=users)
|
2016-07-08 01:12:28 +00:00
|
|
|
factures = Facture.objects.filter(user__pseudo=users)
|
|
|
|
bans = Ban.objects.filter(user__pseudo=users)
|
|
|
|
whitelists = Whitelist.objects.filter(user__pseudo=users)
|
2016-07-05 17:34:57 +00:00
|
|
|
list_droits = Right.objects.filter(user=users)
|
2016-07-08 01:12:28 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
'users/profil.html',
|
|
|
|
{
|
|
|
|
'user': users,
|
2016-07-18 03:30:35 +00:00
|
|
|
'machines_list': machines,
|
2016-07-08 01:12:28 +00:00
|
|
|
'facture_list': factures,
|
|
|
|
'ban_list': bans,
|
|
|
|
'white_list': whitelists,
|
2016-07-09 15:16:44 +00:00
|
|
|
'list_droits': list_droits,
|
2016-07-08 01:40:04 +00:00
|
|
|
}
|
|
|
|
)
|
2016-07-03 16:09:58 +00:00
|
|
|
|
2016-07-20 10:06:33 +00:00
|
|
|
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)
|
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
def process(request, token):
|
|
|
|
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
|
|
|
req = get_object_or_404(valid_reqs, token=token)
|
|
|
|
|
|
|
|
if req.type == Request.PASSWD:
|
|
|
|
return process_passwd(request, req)
|
|
|
|
elif req.type == Request.EMAIL:
|
|
|
|
return process_email(request, req=req)
|
|
|
|
else:
|
2016-07-20 10:06:33 +00:00
|
|
|
messages.error(request, "Entrée incorrecte, contactez un admin")
|
|
|
|
redirect("/")
|
2016-07-20 01:53:46 +00:00
|
|
|
|
|
|
|
def process_passwd(request, req):
|
|
|
|
u_form = PassForm(request.POST or None)
|
|
|
|
user = req.user
|
|
|
|
if u_form.is_valid():
|
|
|
|
return password_change_action(u_form, user, request, req=req)
|
|
|
|
return form({'userform': u_form}, 'users/user.html', request)
|