fix render user info

This commit is contained in:
Cayo Puigdefabregas 2023-12-11 18:40:37 +01:00
parent 69f1b003bf
commit f296cd020c
3 changed files with 30 additions and 28 deletions

View File

@ -168,7 +168,7 @@ class OAuth2VPToken(models.Model):
authorization = models.ForeignKey( authorization = models.ForeignKey(
Authorization, Authorization,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name='oauth2vptoken', related_name='vp_tokens',
null=True, null=True,
) )
@ -176,10 +176,7 @@ class OAuth2VPToken(models.Model):
code = kwargs.pop("code", None) code = kwargs.pop("code", None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.authorization = get_object_or_404( self.authorization = Authorization.objects.filter(code=code).first()
Authorization,
code=code
)
def verifing(self): def verifing(self):
self.result_verify = verify_presentation(self.vp_token) self.result_verify = verify_presentation(self.vp_token)

View File

@ -40,7 +40,6 @@ class AuthorizeView(UserView, FormView):
return kwargs return kwargs
def form_valid(self, form): def form_valid(self, form):
# import pdb; pdb.set_trace()
authorization = form.save() authorization = form.save()
if not authorization or authorization.status_code != 200: if not authorization or authorization.status_code != 200:
messages.error(self.request, _("Error sending credential!")) messages.error(self.request, _("Error sending credential!"))
@ -67,7 +66,6 @@ class AuthorizeView(UserView, FormView):
return super().form_valid(form) return super().form_valid(form)
def get_org(self): def get_org(self):
# import pdb; pdb.set_trace()
client_id = self.request.GET.get("client_id") client_id = self.request.GET.get("client_id")
if not client_id: if not client_id:
raise Http404("Organization not found!") raise Http404("Organization not found!")
@ -93,7 +91,6 @@ class VerifyView(View):
return HttpResponse(res) return HttpResponse(res)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
# import pdb; pdb.set_trace()
code = self.request.POST.get("code") code = self.request.POST.get("code")
vp_tk = self.request.POST.get("vp_token") vp_tk = self.request.POST.get("vp_token")
@ -107,6 +104,8 @@ class VerifyView(View):
organization=org, organization=org,
code=code code=code
) )
if not vp_token.authorization:
raise Http404("Page not Found!")
vp_token.verifing() vp_token.verifing()
response = vp_token.get_response_verify() response = vp_token.get_response_verify()

View File

@ -38,7 +38,6 @@ class ContractView(FormView):
success_url = reverse_lazy('promotion:thanks') success_url = reverse_lazy('promotion:thanks')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# import pdb; pdb.set_trace()
self.context = super().get_context_data(**kwargs) self.context = super().get_context_data(**kwargs)
code = self.request.GET.get("code") code = self.request.GET.get("code")
self.get_discount(code) self.get_discount(code)
@ -50,29 +49,34 @@ class ContractView(FormView):
"total": 25.0 "total": 25.0
}) })
if self.promotion: if self.promotion:
self.context['sim'] = self.context.get_discount(self.context["sim"]) self.context['sim'] = self.promotion.get_discount(self.context["sim"])
self.context['mensual'] = self.context.get_discount(self.context["mensual"]) self.context['mensual'] = self.promotion.get_discount(self.context["mensual"])
self.context['total'] = self.context.get_discount(self.context["total"]) self.context['total'] = self.promotion.get_discount(self.context["total"])
if self.vp_token:
self.context['verificable_presentation'] = self.vp_token
return self.context return self.context
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super().get_form_kwargs() kwargs = super().get_form_kwargs()
code = self.request.GET.get("code")
self.get_discount(code)
if not self.vp_token: if not self.vp_token:
return kwargs return kwargs
self.vp_token.get_user_info() self.vp_token.get_user_info()
kwargs['verificable_presentation'] = self.vp_token kwargs['initial']["nif"] = self.vp_token.user_info.get("nif", '')
kwargs["nif"] = self.vp_token.user_info.get("nif", '') kwargs['initial']["name"] = self.vp_token.user_info.get("name", '')
kwargs["name"] = self.vp_token.user_info.get("name", '') kwargs['initial']["first_last_name"] = self.vp_token.user_info.get("first_last_name", '')
kwargs["first_last_name"] = self.vp_token.user_info.get("first_last_name", '') kwargs['initial']["second_last_name"] = self.vp_token.user_info.get("second_last_name", '')
kwargs["second_last_name"] = self.vp_token.user_info.get("second_last_name", '') kwargs['initial']["email"] = self.vp_token.user_info.get("email", '')
kwargs["email"] = self.vp_token.user_info.get("email", '') kwargs['initial']["email_repeat"] = self.vp_token.user_info.get("email", '')
kwargs["email_repeat"] = self.vp_token.user_info.get("email", '') kwargs['initial']["telephone"] = self.vp_token.user_info.get("telephone", '')
kwargs["telephone"] = self.vp_token.user_info.get("telephone", '') kwargs['initial']["birthday"] = self.vp_token.user_info.get("birthday", '')
kwargs["birthday"] = self.vp_token.user_info.get("birthday", '') kwargs['initial']["gen"] = self.vp_token.user_info.get("gen", '')
kwargs["gen"] = self.vp_token.user_info.get("gen", '') kwargs['initial']["lang"] = self.vp_token.user_info.get("lang", '')
kwargs["lang"] = self.vp_token.user_info.get("lang", '')
return kwargs return kwargs
def form_valid(self, form): def form_valid(self, form):
@ -81,16 +85,18 @@ class ContractView(FormView):
def get_discount(self, code): def get_discount(self, code):
if not code: if not code:
return return
if self.authorization:
return
self.authorization = Authorization.objects.filter( self.authorization = Authorization.objects.filter(
code=code, code=code,
code_unused=False code_used=False
).first() ).first()
if self.authorization: if self.authorization:
if self.authorization.promotions: if self.authorization.promotions.exists():
self.promotion = self.authorization.promotionsp[-1] self.promotion = self.authorization.promotions.all()[0]
if self.authorization.vp_tokens: if self.authorization.vp_tokens.exists():
self.vp_tokens = self.authorization.vp_tokens[-1] self.vp_token = self.authorization.vp_tokens.all()[0]
class SelectWalletView(FormView): class SelectWalletView(FormView):