Skip to content

Commit

Permalink
lost my card !
Browse files Browse the repository at this point in the history
  • Loading branch information
Nasjoe committed Jun 11, 2024
1 parent 98f489b commit cb8ba73
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 49 deletions.
10 changes: 0 additions & 10 deletions BaseBillet/templates/htmx/fragments/card.html

This file was deleted.

24 changes: 24 additions & 0 deletions BaseBillet/templates/htmx/fragments/cards.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load tibitags %}
{% load i18n %}
{% load static %}

{% for card in cards %}
<div class="card card-background card-background-mask-dark align-items-start mt-4 w-75 mx-auto">
<div class="full-background cursor-pointer"
style="background-image: url({{ card.origin.img | randCardImg }})"></div>
<div class="card-body">
<h6 class="text-white mb-0">Number : {{ card.number_printed }}</h6>
<p class="text-white">Origin : {{ card.origin.place.name }}</p>
<p class="text-white">Génération : {{ card.origin.generation }}</p>
</div>
</div>
<h5 class="mx-auto mt-2">{% translate "If you've lost your card, please report it. Your account will not be deleted, and you will keep your tokens and memberships. You can request and scan a new blank card at the front desk of your favorite venue :)" %}</h5>
<button type="submit" class="btn bg-gradient-danger btn-lg mt-2 p-4 mb-2 w-75 mx-auto"
role="button"
aria-label="valider formulaire adhésion"
hx-get="/my_account/{{ card.number_printed }}/lost_my_card/"
hx-indicator="#tibillet-spinner">
{% translate "I LOST MY CARD NUMBER" %} {{ card.number_printed }}
</button>
{% endfor %}

17 changes: 14 additions & 3 deletions BaseBillet/templates/htmx/fragments/my_account_profil.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}

<div class="container pt-5">
<h1>{% translate "My account" %}</h1>
<h1>{% translate "My cards" %}</h1>
{% if not user.email_valid %}
{% translate "Thanks to valid your email for activate your accont" %}

Expand All @@ -11,6 +12,16 @@ <h1>{% translate "My account" %}</h1>
{% translate "Resend validation email" %}
</button>
{% else %}
{% translate "email verified" %}
{# {% translate "email verified" %}#}
<div hx-get="/my_account/my_cards/" hx-trigger="revealed" class="mt-4">
<span>{% translate "Loading NFC Card info" %}</span>
<div class="d-flex justify-content-center align-items-center ">
<div class="spinner-border text-info"
role="status"
></div>
</div>
</div>


{% endif %}
</div>
</div>
5 changes: 5 additions & 0 deletions BaseBillet/templatetags/tibitags.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def randImg(value):
return f"/static/images/404-{randint(1,9)}.jpg"
return value

@register.filter
def randCardImg(value):
if not value :
return f"/static/images/404-Card-1.jpg"
return value
# @register.filter
# def wallet_name(wallet):
# return wallet.uuid
26 changes: 24 additions & 2 deletions BaseBillet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,30 @@ def wallet(self, request: HttpRequest) -> HttpResponse:
template_context['header'] = False
return render(request, "htmx/fragments/my_account_wallet.html", context=template_context)

# @action(detail=False, methods=['GET'])
# def my_card(self, request):
@action(detail=False, methods=['GET'])
def my_cards(self, request):
if request.user.email_valid:
fedowAPI = FedowAPI()
cards = fedowAPI.NFCcard.retrieve_card_by_signature(request.user)
context = {
'cards': cards
}
return render(request, "htmx/fragments/cards.html", context=context)
else :
logger.warning("User email not active")

@action(detail=True, methods=['GET'])
def lost_my_card(self, request, pk):
if request.user.email_valid:
fedowAPI = FedowAPI()
lost_card_report = fedowAPI.NFCcard.lost_my_card_by_signature(request.user, number_printed=pk)
if lost_card_report :
messages.add_message(request, messages.SUCCESS, _("Your wallet has been detached from this card. You can scan a new one to link it again."))
else :
messages.add_message(request, messages.ERROR, _("Error when detaching your card. Contact an administrator."))
return HttpResponseClientRedirect('/my_account/')
else :
logger.warning("User email not active")

@action(detail=False, methods=['GET'])
def tokens_table(self, request):
Expand Down
4 changes: 2 additions & 2 deletions bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ alias cel="poetry run celery -A TiBillet worker -l INFO"

alias test="poetry run python /DjangoFiles/manage.py test"

alias mmes="django-admin makemessages -l en && django-admin makemessages -l fr"
alias cmes="django-admin compilemessages"
alias mmes="poetry run django-admin makemessages -l en && django-admin makemessages -l fr"
alias cmes="poetry run django-admin compilemessages"

tibinstall() {
poetry run python /DjangoFiles/manage.py collectstatic
Expand Down
31 changes: 31 additions & 0 deletions fedow_connect/fedow_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,37 @@ def __init__(self, fedow_config: FedowConfig or None = None):
if fedow_config is None:
self.config = FedowConfig.get_solo()

def retrieve_card_by_signature(self, user: TibilletUser):
response_get_card = _get(
self.fedow_config,
user=user,
path=f'card/retrieve_card_by_signature',
)

if not response_get_card.status_code == 200:
logger.error(f"retrieve_by_signature ERRORS : {response_get_card.status_code}")
raise Exception(f"retrieve_by_signature ERRORS : {response_get_card.status_code}")

card_serialized = CardValidator(data=response_get_card.json(), many=True)
if card_serialized.is_valid():
return card_serialized.validated_data
else:
logger.error(f"retrieve_by_signature card_serialized ERRORS : {card_serialized.errors}")
raise Exception(f"retrieve_by_signature card_serialized ERRORS : {card_serialized.errors}")

def lost_my_card_by_signature(self, user, number_printed):
response_lost_my_card = _post(
self.fedow_config,
user=user,
path=f'card/lost_my_card_by_signature',
data={'number_printed': number_printed}
)

if not response_lost_my_card.status_code == 200:
logger.error(f"retrieve_by_signature ERRORS : {response_lost_my_card.status_code}")
raise Exception(f"retrieve_by_signature ERRORS : {response_lost_my_card.status_code}")
return True

def qr_retrieve(self, qrcode_uuid: uuid4):
# On vérifie que l'uuid soit bien un uuid :
checked_uuid = uuid.UUID(str(qrcode_uuid))
Expand Down
64 changes: 48 additions & 16 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-09 20:13+0000\n"
"POT-Creation-Date: 2024-06-11 13:03+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -865,12 +865,12 @@ msgid "Réservation validée"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_membership.html:4
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:14
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:18
msgid "Loading tokens"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:3
msgid "My profil"
msgid "My account"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:5
Expand All @@ -881,15 +881,19 @@ msgstr ""
msgid "Resend validation email"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:16
msgid "My card"
#: BaseBillet/templates/htmx/fragments/my_account_profil.html:14
msgid "email verified"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:9
#: BaseBillet/templates/htmx/fragments/my_account_profil.html:17
msgid "Loading NFC Card info"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:12
msgid "Refill my wallet"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:30
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:35
msgid "Show the last transactions"
msgstr ""

Expand Down Expand Up @@ -946,11 +950,11 @@ msgstr ""
msgid "Terms and Conditions"
msgstr ""

#: BaseBillet/templates/htmx/views/inscription.html:77
#: BaseBillet/templates/htmx/views/inscription.html:78
msgid "Sign up"
msgstr ""

#: BaseBillet/templates/htmx/views/inscription.html:83
#: BaseBillet/templates/htmx/views/inscription.html:84
msgid ""
"Learn more about TiBillet, a free and privacy-friendly software for "
"cooperatives networks :"
Expand Down Expand Up @@ -991,22 +995,50 @@ msgid ""
"compte. Vous trouverez la facture en pièce jointe."
msgstr ""

#: BaseBillet/views.py:201 BaseBillet/views.py:254
#: BaseBillet/views.py:132
msgid ""
"To access your space, please validate\n"
"your email address. Don't forget to check your spam!"
msgstr ""

#: BaseBillet/views.py:191 BaseBillet/views.py:244
msgid ""
"Merci de valider votre email pour acceder à toute les fonctionnalitées de "
"votre espace profil."
"Please validate your email to access all the features of your profile area."
msgstr ""

#: BaseBillet/views.py:227
#: BaseBillet/views.py:217
msgid ""
"Vous semblez déja posséder une carte TiBillet en lien avec votre "
"portefeuille. Merci de la révoquer d'abord dans votre espace profil."
"You seem to already have a TiBillet card linked to your wallet. Please "
"revoke it first in your profile area to link a new one."
msgstr ""

#: BaseBillet/views.py:232
#: BaseBillet/views.py:222
msgid "Not valid"
msgstr ""

#: BaseBillet/views.py:363
msgid "Refilled wallet"
msgstr ""

#: BaseBillet/views.py:365
msgid "Payment verification error"
msgstr ""

#: BaseBillet/views.py:473
#, python-brace-format
msgid ""
"Your subscription has been validated. You will receive a confirmation email "
"at {email}. Thank you very much!"
msgstr ""

#: BaseBillet/views.py:475
msgid "Your payment is awaiting validation."
msgstr ""

#: BaseBillet/views.py:478
msgid "An error has occurred, please contact the administrator."
msgstr ""

#: Customers/models.py:18 MetaBillet/models.py:165
msgid "Artiste"
msgstr ""
Expand Down
64 changes: 48 additions & 16 deletions locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-09 20:13+0000\n"
"POT-Creation-Date: 2024-06-11 13:03+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -865,12 +865,12 @@ msgid "Réservation validée"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_membership.html:4
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:14
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:18
msgid "Loading tokens"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:3
msgid "My profil"
msgid "My account"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:5
Expand All @@ -881,15 +881,19 @@ msgstr ""
msgid "Resend validation email"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_profil.html:16
msgid "My card"
#: BaseBillet/templates/htmx/fragments/my_account_profil.html:14
msgid "email verified"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:9
#: BaseBillet/templates/htmx/fragments/my_account_profil.html:17
msgid "Loading NFC Card info"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:12
msgid "Refill my wallet"
msgstr ""

#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:30
#: BaseBillet/templates/htmx/fragments/my_account_wallet.html:35
msgid "Show the last transactions"
msgstr ""

Expand Down Expand Up @@ -946,11 +950,11 @@ msgstr "J'accepte les"
msgid "Terms and Conditions"
msgstr "CGU/CGV"

#: BaseBillet/templates/htmx/views/inscription.html:77
#: BaseBillet/templates/htmx/views/inscription.html:78
msgid "Sign up"
msgstr "S'enregistrer"

#: BaseBillet/templates/htmx/views/inscription.html:83
#: BaseBillet/templates/htmx/views/inscription.html:84
msgid ""
"Learn more about TiBillet, a free and privacy-friendly software for "
"cooperatives networks :"
Expand Down Expand Up @@ -993,22 +997,50 @@ msgid ""
"compte. Vous trouverez la facture en pièce jointe."
msgstr ""

#: BaseBillet/views.py:201 BaseBillet/views.py:254
#: BaseBillet/views.py:132
msgid ""
"To access your space, please validate\n"
"your email address. Don't forget to check your spam!"
msgstr ""

#: BaseBillet/views.py:191 BaseBillet/views.py:244
msgid ""
"Merci de valider votre email pour acceder à toute les fonctionnalitées de "
"votre espace profil."
"Please validate your email to access all the features of your profile area."
msgstr ""

#: BaseBillet/views.py:227
#: BaseBillet/views.py:217
msgid ""
"Vous semblez déja posséder une carte TiBillet en lien avec votre "
"portefeuille. Merci de la révoquer d'abord dans votre espace profil."
"You seem to already have a TiBillet card linked to your wallet. Please "
"revoke it first in your profile area to link a new one."
msgstr ""

#: BaseBillet/views.py:232
#: BaseBillet/views.py:222
msgid "Not valid"
msgstr ""

#: BaseBillet/views.py:363
msgid "Refilled wallet"
msgstr ""

#: BaseBillet/views.py:365
msgid "Payment verification error"
msgstr ""

#: BaseBillet/views.py:473
#, python-brace-format
msgid ""
"Your subscription has been validated. You will receive a confirmation email "
"at {email}. Thank you very much!"
msgstr ""

#: BaseBillet/views.py:475
msgid "Your payment is awaiting validation."
msgstr ""

#: BaseBillet/views.py:478
msgid "An error has occurred, please contact the administrator."
msgstr ""

#: Customers/models.py:18 MetaBillet/models.py:165
msgid "Artiste"
msgstr ""
Expand Down

0 comments on commit cb8ba73

Please sign in to comment.