diff --git a/idhub/templates/idhub/user/credentials_presentation.html b/idhub/templates/idhub/user/credentials_presentation.html
index b94e3c8..59dd4f4 100644
--- a/idhub/templates/idhub/user/credentials_presentation.html
+++ b/idhub/templates/idhub/user/credentials_presentation.html
@@ -20,6 +20,7 @@
{% endif %}
+{% if form.if_credentials %}
+{% else %}
+
+
+ {% trans 'Sorry no there are credentials to present' %}
+
+
+{% endif %}
{% endblock %}
diff --git a/idhub/user/forms.py b/idhub/user/forms.py
index 654a936..ca7ed99 100644
--- a/idhub/user/forms.py
+++ b/idhub/user/forms.py
@@ -130,6 +130,7 @@ class DemandAuthorizationForm(forms.Form):
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
+ self.if_credentials = kwargs.pop('if_credentials', None)
super().__init__(*args, **kwargs)
self.fields['organization'].choices = [
(x.id, x.name) for x in Organization.objects.exclude(
diff --git a/idhub/user/views.py b/idhub/user/views.py
index 97e3993..defebb2 100644
--- a/idhub/user/views.py
+++ b/idhub/user/views.py
@@ -427,9 +427,24 @@ class DemandAuthorizationView(MyWallet, FormView):
form_class = DemandAuthorizationForm
success_url = reverse_lazy('idhub:user_demand_authorization')
+ def get(self, *args, **kwargs):
+ response = super().get(*args, **kwargs)
+ creds_enable = VerificableCredential.objects.filter(
+ user=self.request.user,
+ status=VerificableCredential.Status.ENABLED.value,
+ ).exists()
+ if not self.if_credentials and creds_enable:
+ return redirect(reverse_lazy('idhub:user_credentials_request'))
+ return response
+
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['user'] = self.request.user
+ self.if_credentials = VerificableCredential.objects.filter(
+ user=self.request.user,
+ status=VerificableCredential.Status.ISSUED.value,
+ ).exists()
+ kwargs['if_credentials'] = self.if_credentials
return kwargs
def form_valid(self, form):