Update card detection logic
This commit is contained in:
parent
c389d0c440
commit
b44e7c300d
|
@ -16,7 +16,7 @@ namespace AfRApay.Web.Backend.Database.Migrations
|
|||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
|
||||
// Detect AfRA door tokens
|
||||
migrationBuilder.Sql("UPDATE Cards SET CardType = 10 WHERE LENGTH(CardId) = 10 AND CardId GLOB '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
// <auto-generated />
|
||||
using AfRApay.Web.Backend.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AfRApay.Web.Backend.Database.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20230519150553_636FBB05-633F-423F-B840-F9B4DE285DF5")]
|
||||
partial class _636FBB05633F423FB840F9B4DE285DF5
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
|
||||
|
||||
modelBuilder.Entity("AfRApay.Web.Backend.Database.Tables.Card", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("NVarChar(255)")
|
||||
.HasColumnName("CardId");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("CardType");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Cards");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AfRApay.Web.Backend.Database.Tables.Config", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("NVarChar(255)")
|
||||
.HasColumnName("Name");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("NVarChar(255)")
|
||||
.HasColumnName("Value");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Config");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AfRApay.Web.Backend.Database.Tables.User", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("ID");
|
||||
|
||||
b.Property<long>("Balance")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("Balance");
|
||||
|
||||
b.Property<string>("LastIdempotencyKey")
|
||||
.HasColumnType("NVarChar(255)")
|
||||
.HasColumnName("LastIdempotencyKey");
|
||||
|
||||
b.Property<string>("Nickname")
|
||||
.IsRequired()
|
||||
.HasColumnType("NVarChar(255)")
|
||||
.HasColumnName("Nickname");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Nickname")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AfRApay.Web.Backend.Database.Tables.Card", b =>
|
||||
{
|
||||
b.HasOne("AfRApay.Web.Backend.Database.Tables.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AfRApay.Web.Backend.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class _636FBB05633F423FB840F9B4DE285DF5 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Revert wrongly detected card types
|
||||
migrationBuilder.Sql("UPDATE Cards SET CardType = 20 WHERE CardType = 21 OR CardType = 23 OR CardType = 24 OR CardType = 25");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -153,19 +153,21 @@ public class CardController : Controller {
|
|||
}
|
||||
|
||||
private Card.CardType GetCardType(string? reader, string cardNumber) => reader switch {
|
||||
// these seem to not be accurate yet
|
||||
// these seem not be reliable
|
||||
//"pn532-iso14443a" when cardNumber.Length == 8 => Card.CardType.NfcMifareClassic,
|
||||
//"pn532-iso14443a" when cardNumber.Length == 12 && cardNumber.EndsWith("0218") => Card.CardType.NfcOvChipkaart,
|
||||
//"pn532-iso14443a" when cardNumber.Length == 14 && cardNumber.StartsWith("04") && cardNumber.EndsWith("80") => Card.CardType.NfcItso,
|
||||
|
||||
"pn532-iso14443a" when cardNumber.Length == 14 && (cardNumber.EndsWith("5e80") || cardNumber.EndsWith("4e80")) => Card.CardType.NfcTflOyster,
|
||||
"pn532-iso14443a" => Card.CardType.NfcGeneric,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0112") => Card.CardType.FeliCaSuica,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0101") => Card.CardType.FeliCaPasmo,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0139") => Card.CardType.FeliCaApplePay,
|
||||
"pn532-felica" => Card.CardType.FeliCaGeneric,
|
||||
"rdm6300" => Card.CardType.Rfid125KhzGeneric,
|
||||
_ => Card.CardType.Unknown
|
||||
//"pn532-iso14443a" when [???] => Card.CardType.NfcContactless,
|
||||
|
||||
"pn532-iso14443a" when cardNumber.Length == 14 && cardNumber.EndsWith("4e80") => Card.CardType.NfcTflOyster,
|
||||
"pn532-iso14443a" when cardNumber.Length == 14 && cardNumber.EndsWith("5e80") => Card.CardType.NfcTflOyster,
|
||||
"pn532-iso14443a" when cardNumber.Length == 14 && cardNumber.EndsWith("5f80") => Card.CardType.NfcTflOyster,
|
||||
"pn532-iso14443a" => Card.CardType.NfcGeneric,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0112") => Card.CardType.FeliCaSuica,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0101") => Card.CardType.FeliCaPasmo,
|
||||
"pn532-felica" when cardNumber.Length == 16 && cardNumber.StartsWith("0139") => Card.CardType.FeliCaApplePay,
|
||||
"pn532-felica" => Card.CardType.FeliCaGeneric,
|
||||
"rdm6300" => Card.CardType.Rfid125KhzGeneric,
|
||||
_ => Card.CardType.Unknown
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue