mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Validateur nazi pour empécher de mettre des dates de fins de ban dans le passé
This commit is contained in:
parent
d6e03b84fb
commit
ff2b4cb0d2
4 changed files with 40 additions and 0 deletions
Binary file not shown.
|
@ -24,6 +24,16 @@ def end_adhesion(user):
|
|||
date_max = Cotisation.objects.all().filter(facture=Facture.objects.all().filter(user=user)).aggregate(Max('date_end'))['date_end__max']
|
||||
return date_max
|
||||
|
||||
def is_adherent(user):
|
||||
""" Renvoie si un user est à jour de cotisation """
|
||||
end = end_adhesion(user)
|
||||
if not end:
|
||||
return False
|
||||
elif end < timezone.now():
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def create_cotis(facture, user, article):
|
||||
""" Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée"""
|
||||
cotisation=Cotisation(facture=facture)
|
||||
|
|
|
@ -2,6 +2,8 @@ from django.db import models
|
|||
from django.forms import ModelForm
|
||||
from django import forms
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
class User(models.Model):
|
||||
STATE_ACTIVE = 0
|
||||
STATE_DEACTIVATED = 1
|
||||
|
@ -119,3 +121,9 @@ class BanForm(ModelForm):
|
|||
class Meta:
|
||||
model = Ban
|
||||
exclude = ['user']
|
||||
|
||||
def clean_date_end(self):
|
||||
date_end = self.cleaned_data['date_end']
|
||||
if date_end < timezone.now():
|
||||
raise forms.ValidationError("Triple buse, la date de fin ne peut pas être avant maintenant... Re2o ne voyage pas dans le temps")
|
||||
return date_end
|
||||
|
|
|
@ -6,9 +6,12 @@ from django.shortcuts import render_to_response, get_object_or_404
|
|||
from django.core.context_processors import csrf
|
||||
from django.template import Context, RequestContext, loader
|
||||
from django.contrib import messages
|
||||
from django.db.models import Max
|
||||
from django.utils import timezone
|
||||
|
||||
from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm
|
||||
from users.forms import PassForm
|
||||
from cotisations.views import is_adherent
|
||||
|
||||
from re2o.login import makeSecret, hashNT
|
||||
|
||||
|
@ -17,6 +20,23 @@ def end_ban(user):
|
|||
date_max = Ban.objects.all().filter(user=user).aggregate(Max('date_end'))['date_end__max']
|
||||
return date_max
|
||||
|
||||
def is_ban(user):
|
||||
""" Renvoie si un user est banni ou non """
|
||||
end = end_ban(user)
|
||||
if not end:
|
||||
return False
|
||||
elif end < timezone.now():
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def has_access(user):
|
||||
""" Renvoie si un utilisateur a accès à internet"""
|
||||
if user.state == 0 and not is_ban(user) and is_adherent(user):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def form(ctx, template, request):
|
||||
c = ctx
|
||||
c.update(csrf(request))
|
||||
|
@ -103,6 +123,8 @@ def add_ban(request, userid):
|
|||
ban.save()
|
||||
messages.success(request, "Bannissement ajouté")
|
||||
return redirect("/users/")
|
||||
if is_ban(user):
|
||||
messages.error(request, u"Attention, cet utilisateur a deja un bannissement actif" )
|
||||
return form({'userform': ban}, 'users/user.html', request)
|
||||
|
||||
def edit_ban(request, banid):
|
||||
|
|
Loading…
Reference in a new issue