diff --git a/idhub/user/views.py b/idhub/user/views.py index 77ca3ec..d7b1cb3 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -144,6 +144,9 @@ class CredentialsRequestView(MyWallet, FormView): messages.success(self.request, _("The credential was issued successfully!")) Event.set_EV_CREDENTIAL_ISSUED_FOR_USER(cred) Event.set_EV_CREDENTIAL_ISSUED(cred) + url = self.request.session.pop('next_url', None) + if url: + return redirect(url) else: messages.error(self.request, _("The credential does not exist!")) return super().form_valid(form) diff --git a/oidc4vp/forms.py b/oidc4vp/forms.py index 5f6f6df..b3c4c9e 100644 --- a/oidc4vp/forms.py +++ b/oidc4vp/forms.py @@ -23,8 +23,10 @@ class AuthorizeForm(forms.Form): reg = r'({})'.format('|'.join(self.presentation_definition)) - self.credentials = self.user.vcredentials.filter( + self.all_credentials = self.user.vcredentials.filter( schema__type__iregex=reg, + ) + self.credentials = self.all_credentials.filter( status=VerificableCredential.Status.ISSUED.value ) super().__init__(*args, **kwargs) diff --git a/oidc4vp/views.py b/oidc4vp/views.py index 3e6f0f3..a62e462 100644 --- a/oidc4vp/views.py +++ b/oidc4vp/views.py @@ -27,6 +27,12 @@ class AuthorizeView(UserView, FormView): form_class = AuthorizeForm success_url = reverse_lazy('idhub:user_demand_authorization') + def get(self, request, *args, **kwargs): + response = super().get(request, *args, **kwargs) + if self.request.session.get('next_url'): + 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 @@ -38,6 +44,12 @@ class AuthorizeView(UserView, FormView): kwargs["org"] = self.get_org() kwargs["code"] = self.request.GET.get('code') return kwargs + + def get_form(self, form_class=None): + form = super().get_form(form_class=form_class) + if form.all_credentials.exists() and not form.credentials.exists(): + self.request.session['next_url'] = self.request.get_full_path() + return form def form_valid(self, form): authorization = form.save()