fix bugs with redirections

This commit is contained in:
Cayo Puigdefabregas 2024-02-21 11:38:00 +01:00
parent 010cd169f7
commit 910aa7c888
2 changed files with 8 additions and 6 deletions

View File

@ -18,6 +18,7 @@ from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib import messages from django.contrib import messages
from django.core.cache import cache
from utils import credtools from utils import credtools
from idhub_auth.models import User from idhub_auth.models import User
from idhub_auth.forms import ProfileForm from idhub_auth.forms import ProfileForm
@ -90,7 +91,7 @@ class EncryptionKeyView(AdminView, FormView):
success_url = reverse_lazy('idhub:admin_dashboard') success_url = reverse_lazy('idhub:admin_dashboard')
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if self.admin_validated: if cache.get("KEY_DIDS"):
return redirect(self.success_url) return redirect(self.success_url)
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)

View File

@ -21,6 +21,7 @@ from django.views.generic.edit import (
) )
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.core.cache import cache
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib import messages from django.contrib import messages
@ -169,7 +170,7 @@ class WaitingView(UserView, TemplateView):
success_url = reverse_lazy('idhub:user_dashboard') success_url = reverse_lazy('idhub:user_dashboard')
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if self.admin_validated: if cache.get("KEY_DIDS"):
return redirect(self.success_url) return redirect(self.success_url)
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
@ -204,7 +205,7 @@ class CredentialPdfView(MyWallet, TemplateView):
file_name = "certificate.pdf" file_name = "certificate.pdf"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if not self.admin_validated: if not cache.get("KEY_DIDS"):
return redirect(reverse_lazy('idhub:user_dashboard')) return redirect(reverse_lazy('idhub:user_dashboard'))
pk = kwargs['pk'] pk = kwargs['pk']
self.user = self.request.user self.user = self.request.user
@ -231,7 +232,7 @@ class CredentialPdfView(MyWallet, TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
this_folder = str(Path.cwd()) # this_folder = str(Path.cwd())
path_img_sig = "idhub/static/images/4_Model_Certificat_html_58d7f7eeb828cf29.jpg" path_img_sig = "idhub/static/images/4_Model_Certificat_html_58d7f7eeb828cf29.jpg"
img_signature = next(Path.cwd().glob(path_img_sig)) img_signature = next(Path.cwd().glob(path_img_sig))
with open(img_signature, 'rb') as _f: with open(img_signature, 'rb') as _f:
@ -376,8 +377,8 @@ class CredentialsRequestView(MyWallet, FormView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = super().get(request, *args, **kwargs) response = super().get(request, *args, **kwargs)
if not self.admin_validated: if not cache.get("KEY_DIDS"):
return redirect(reverse_lazy('idhub:user_dashboard')) return redirect(reverse_lazy('idhub:user_waiting'))
return response return response
def get_form_kwargs(self): def get_form_kwargs(self):