Skip to content

Commit

Permalink
Change Card Lookup Ordering
Browse files Browse the repository at this point in the history
Preferentially search for CSNs, since the magstripe regexp is
greedier and will match on nfc cardreaders outputting in decimal.
  • Loading branch information
merichar authored and timparenti committed Apr 6, 2019
1 parent 876f38f commit abdd1ef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def self.find_by_card(card_number, lookup_only = false)
return person #self.find_by_andrewid(card_number)
elsif !lookup_only and !CarnegieMellonPerson.find_by_andrewid(card_number.downcase).blank?
return self.find_or_create_by(andrewid: card_number.downcase)
# Decimal CSN from MIFARE reader (10 decimal digits)
elsif card_number[/\A\d{10}\z/]
# Must pad to 8 hex digits for the card translation service
andrewid = CarnegieMellonIDCard.get_andrewid_by_card_csn(card_number.to_i.to_s(16).rjust(8,"0"))
return self.find_or_create_by(andrewid: andrewid) unless andrewid.blank?
# PIK number from magstripe or printed on card (9 decimal digits, allow leading % character and trailing data)
elsif card_number[/^%?\d{9}/]
andrewid = CarnegieMellonIDCard.get_andrewid_by_card_id(card_number)
Expand All @@ -123,11 +128,6 @@ def self.find_by_card(card_number, lookup_only = false)
elsif card_number[/\A[0-9a-fA-F]{8}\z/]
andrewid = CarnegieMellonIDCard.get_andrewid_by_card_csn(card_number)
return self.find_or_create_by(andrewid: andrewid) unless andrewid.blank?
# Decimal CSN from MIFARE reader (10 decimal digits)
elsif card_number[/\A\d{10}\z/]
# Must pad to 8 hex digits for the card translation service
andrewid = CarnegieMellonIDCard.get_andrewid_by_card_csn(card_number.to_i.to_s(16).rjust(8,"0"))
return self.find_or_create_by(andrewid: andrewid) unless andrewid.blank?
end
end

Expand Down

0 comments on commit abdd1ef

Please sign in to comment.