mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
Vue verify
This commit is contained in:
parent
ebb4ca36b2
commit
e455859e13
4 changed files with 30 additions and 5 deletions
|
@ -263,7 +263,7 @@ def get_config(request):
|
||||||
"""
|
"""
|
||||||
Load the config and return it in a json format
|
Load the config and return it in a json format
|
||||||
"""
|
"""
|
||||||
gp,_ = GeneralPreferences.objects.get_or_create(pk=1)
|
gp,_ = GeneralPreferences.objects.get_or_create(pk=1).defer("statutes", "rules", "menu")
|
||||||
data = json.dumps(model_to_dict(gp))
|
data = json.dumps(model_to_dict(gp))
|
||||||
return HttpResponse(data, content_type='application/json')
|
return HttpResponse(data, content_type='application/json')
|
||||||
|
|
|
@ -75,14 +75,22 @@ class Profile(models.Model):
|
||||||
debit = models.DecimalField(max_digits=7, decimal_places=2, default=0)
|
debit = models.DecimalField(max_digits=7, decimal_places=2, default=0)
|
||||||
school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True)
|
school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True)
|
||||||
cotisationEnd = models.DateTimeField(blank=True, null=True)
|
cotisationEnd = models.DateTimeField(blank=True, null=True)
|
||||||
|
date_verified = models.DateTimeField(blank=True, null=True)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_verified(self):
|
||||||
|
"""
|
||||||
|
Test if a user is verified
|
||||||
|
"""
|
||||||
|
return self.date_verified is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_adherent(self):
|
def is_adherent(self):
|
||||||
"""
|
"""
|
||||||
Test if a user is adherent
|
Test if a user is adherent
|
||||||
"""
|
"""
|
||||||
if(self.cotisationEnd and self.cotisationEnd > timezone.now()):
|
if(self.is_verified and self.cotisationEnd and self.cotisationEnd > timezone.now()):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -45,4 +45,5 @@ urlpatterns = [
|
||||||
path('allMenus/<int:pk>/<int:page>', views.all_menus, name="allMenus"),
|
path('allMenus/<int:pk>/<int:page>', views.all_menus, name="allMenus"),
|
||||||
path('exportCSV', views.export_csv, name="exportCSV"),
|
path('exportCSV', views.export_csv, name="exportCSV"),
|
||||||
path('switchActivateUser/<int:pk>', views.switch_activate_user, name="switchActivateUser"),
|
path('switchActivateUser/<int:pk>', views.switch_activate_user, name="switchActivateUser"),
|
||||||
|
path('verify/<int:pk>', views.verify, name="verify")
|
||||||
]
|
]
|
||||||
|
|
|
@ -20,6 +20,10 @@ from .models import CotisationHistory, WhiteListHistory, School
|
||||||
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm, ExportForm
|
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm, ExportForm
|
||||||
from gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
|
from gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
|
||||||
|
|
||||||
|
|
||||||
|
from django.contrib.auth.forms import SetPasswordForm
|
||||||
|
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
def loginView(request):
|
def loginView(request):
|
||||||
"""
|
"""
|
||||||
|
@ -177,8 +181,6 @@ def profile(request, pk):
|
||||||
if quantities_pre[k]/totQ >= 0.01:
|
if quantities_pre[k]/totQ >= 0.01:
|
||||||
products.append(products_pre[k])
|
products.append(products_pre[k])
|
||||||
quantities.append(quantities_pre[k])
|
quantities.append(quantities_pre[k])
|
||||||
print(products)
|
|
||||||
print(quantities)
|
|
||||||
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||||
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
|
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||||
return render(request, "users/profile.html",
|
return render(request, "users/profile.html",
|
||||||
|
@ -219,7 +221,6 @@ def createUser(request):
|
||||||
form = CreateUserForm(request.POST or None)
|
form = CreateUserForm(request.POST or None)
|
||||||
if(form.is_valid()):
|
if(form.is_valid()):
|
||||||
user = form.save(commit=False)
|
user = form.save(commit=False)
|
||||||
user.set_password(user.username)
|
|
||||||
user.save()
|
user.save()
|
||||||
user.profile.school = form.cleaned_data['school']
|
user.profile.school = form.cleaned_data['school']
|
||||||
user.save()
|
user.save()
|
||||||
|
@ -512,6 +513,21 @@ def switch_activate_user(request, pk):
|
||||||
user.save()
|
user.save()
|
||||||
messages.success(request, "Le statut de l'utilisateur a bien été changé")
|
messages.success(request, "Le statut de l'utilisateur a bien été changé")
|
||||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||||
|
|
||||||
|
@active_required
|
||||||
|
def verify(request, pk):
|
||||||
|
user = get_object_or_404(User, pk=pk)
|
||||||
|
if(user.profile.is_verified):
|
||||||
|
messages.error(request, "L'utilisateur est déjà vérifié")
|
||||||
|
return redirect(reverse('users:login'))
|
||||||
|
form = SetPasswordForm(user, request.POST or None)
|
||||||
|
if(form.is_valid()):
|
||||||
|
form.save()
|
||||||
|
user.profile.date_verified = datetime.now()
|
||||||
|
user.save()
|
||||||
|
messages.success(request, "Le compte a bien été vérifié")
|
||||||
|
return redirect(reverse('users:login'))
|
||||||
|
return render(request, "users/verify.html", {"user": user, "form": form})
|
||||||
|
|
||||||
########## Groups ##########
|
########## Groups ##########
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue