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
|
||||
"""
|
||||
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))
|
||||
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)
|
||||
school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True)
|
||||
cotisationEnd = models.DateTimeField(blank=True, null=True)
|
||||
date_verified = models.DateTimeField(blank=True, null=True)
|
||||
history = HistoricalRecords()
|
||||
|
||||
@property
|
||||
def is_verified(self):
|
||||
"""
|
||||
Test if a user is verified
|
||||
"""
|
||||
return self.date_verified is not None
|
||||
|
||||
@property
|
||||
def is_adherent(self):
|
||||
"""
|
||||
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
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -45,4 +45,5 @@ urlpatterns = [
|
|||
path('allMenus/<int:pk>/<int:page>', views.all_menus, name="allMenus"),
|
||||
path('exportCSV', views.export_csv, name="exportCSV"),
|
||||
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 gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
|
||||
|
||||
|
||||
from django.contrib.auth.forms import SetPasswordForm
|
||||
|
||||
|
||||
@active_required
|
||||
def loginView(request):
|
||||
"""
|
||||
|
@ -177,8 +181,6 @@ def profile(request, pk):
|
|||
if quantities_pre[k]/totQ >= 0.01:
|
||||
products.append(products_pre[k])
|
||||
quantities.append(quantities_pre[k])
|
||||
print(products)
|
||||
print(quantities)
|
||||
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
|
||||
return render(request, "users/profile.html",
|
||||
|
@ -219,7 +221,6 @@ def createUser(request):
|
|||
form = CreateUserForm(request.POST or None)
|
||||
if(form.is_valid()):
|
||||
user = form.save(commit=False)
|
||||
user.set_password(user.username)
|
||||
user.save()
|
||||
user.profile.school = form.cleaned_data['school']
|
||||
user.save()
|
||||
|
@ -512,6 +513,21 @@ def switch_activate_user(request, pk):
|
|||
user.save()
|
||||
messages.success(request, "Le statut de l'utilisateur a bien été changé")
|
||||
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 ##########
|
||||
|
||||
|
|
Loading…
Reference in a new issue