mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Can identify user on counter with student card UID
This commit is contained in:
parent
9f2a0deeb9
commit
577ad07a2b
41
counter/migrations/0017_studentcard.py
Normal file
41
counter/migrations/0017_studentcard.py
Normal file
@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.13 on 2018-10-17 23:02
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("counter", "0016_producttype_comment")]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="StudentCard",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"uid",
|
||||
models.CharField(max_length=14, unique=True, verbose_name="uid"),
|
||||
),
|
||||
(
|
||||
"customer",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="student_cards",
|
||||
to="counter.Customer",
|
||||
verbose_name="student cards",
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
]
|
@ -732,3 +732,23 @@ class Eticket(models.Model):
|
||||
return hmac.new(
|
||||
bytes(self.secret, "utf-8"), bytes(string, "utf-8"), hashlib.sha1
|
||||
).hexdigest()
|
||||
|
||||
|
||||
class StudentCard(models.Model):
|
||||
"""
|
||||
Alternative way to connect a customer into a counter
|
||||
We are using Mifare DESFire EV1 specs since it's used for izly cards
|
||||
https://www.nxp.com/docs/en/application-note/AN10927.pdf
|
||||
UID is 7 byte long that means 14 hexa characters
|
||||
"""
|
||||
|
||||
UID_SIZE = 14
|
||||
|
||||
uid = models.CharField(_("uid"), max_length=14, unique=True)
|
||||
customer = models.ForeignKey(
|
||||
Customer,
|
||||
related_name="student_cards",
|
||||
verbose_name=_("student cards"),
|
||||
null=False,
|
||||
blank=False,
|
||||
)
|
||||
|
@ -57,6 +57,7 @@ from subscription.models import Subscription
|
||||
from counter.models import (
|
||||
Counter,
|
||||
Customer,
|
||||
StudentCard,
|
||||
Product,
|
||||
Selling,
|
||||
Refilling,
|
||||
@ -121,9 +122,14 @@ class GetUserForm(forms.Form):
|
||||
cleaned_data = super(GetUserForm, self).clean()
|
||||
cus = None
|
||||
if cleaned_data["code"] != "":
|
||||
cus = Customer.objects.filter(
|
||||
account_id__iexact=cleaned_data["code"]
|
||||
).first()
|
||||
if len(cleaned_data["code"]) == StudentCard.UID_SIZE:
|
||||
card = StudentCard.objects.filter(uid=cleaned_data["code"])
|
||||
if card.exists():
|
||||
cus = card.first().customer
|
||||
if cus is None:
|
||||
cus = Customer.objects.filter(
|
||||
account_id__iexact=cleaned_data["code"]
|
||||
).first()
|
||||
elif cleaned_data["id"] is not None:
|
||||
cus = Customer.objects.filter(user=cleaned_data["id"]).first()
|
||||
if cus is None or not cus.can_buy:
|
||||
|
Loading…
Reference in New Issue
Block a user