fix 184 comunication with user, need credentials

This commit is contained in:
Cayo Puigdefabregas 2024-03-11 16:56:11 +01:00
parent 0eec5d40a1
commit fd27e82203
3 changed files with 24 additions and 6 deletions

View File

@ -20,6 +20,7 @@
</div>
</div>
{% endif %}
{% if form.if_credentials %}
<div class="row">
<div class="col-sm-4">
{% bootstrap_form form %}
@ -29,6 +30,12 @@
<a class="btn btn-grey" href="{% url 'idhub:user_credentials' %}">{% trans "Cancel" %}</a>
<input class="btn btn-green-user" type="submit" name="submit" value="{% trans 'Request' %}" />
</div>
{% else %}
<div class="row">
<div class="col-sm-4">
{% trans 'Sorry no there are credentials enabled' %}
</div>
</div>
{% endif %}
</form>
{% endblock %}

View File

@ -86,6 +86,7 @@ class RequestCredentialForm(forms.Form):
self.user = kwargs.pop('user', None)
self.lang = kwargs.pop('lang', None)
self._domain = kwargs.pop('domain', None)
self.if_credentials = kwargs.pop('if_credentials', None)
super().__init__(*args, **kwargs)
self.fields['did'].choices = [
(x.did, x.label) for x in DID.objects.filter(user=self.user)

View File

@ -392,18 +392,26 @@ class CredentialsRequestView(MyWallet, FormView):
form_class = RequestCredentialForm
success_url = reverse_lazy('idhub:user_credentials')
def get(self, request, *args, **kwargs):
response = super().get(request, *args, **kwargs)
if not cache.get("KEY_DIDS"):
return redirect(reverse_lazy('idhub:user_waiting'))
def get(self, *args, **kwargs):
response = super().get(*args, **kwargs)
if not DID.objects.filter(user=self.request.user).exists():
return redirect(reverse_lazy('idhub:user_dids_new'))
return response
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
self.if_credentials = VerificableCredential.objects.filter(
user=self.request.user,
status=VerificableCredential.Status.ENABLED.value,
).exists()
kwargs['user'] = self.request.user
kwargs['lang'] = self.request.LANGUAGE_CODE
domain = "{}://{}".format(self.request.scheme, self.request.get_host())
kwargs['domain'] = domain
kwargs['if_credentials'] = self.if_credentials
return kwargs
def form_valid(self, form):
@ -433,17 +441,19 @@ class DemandAuthorizationView(MyWallet, FormView):
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['user'] = self.request.user
kwargs['if_credentials'] = self.if_credentials
return kwargs