Skip to content

Commit

Permalink
Add NFC CAN number message
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Sep 9, 2024
1 parent 86f1c44 commit eb946f7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/LocalizationKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ enum LocKey : String
case nfcTitle = "nfc-title"
case nfcCANTitle = "nfc-can-title"
case nfcDeviceNoSupport = "nfc-device-no-support"
case nfcCanLocation = "nfc-can-location"
case nfcIncorrectLength = "nfc-incorrect-length"
case nfcHoldNear = "nfc-hold-near"
case nfcMultipleCards = "nfc-multiple-cards"
case nfcInvalidTag = "nfc-invalid-tag"
Expand Down
42 changes: 36 additions & 6 deletions MoppApp/MoppApp/NFCEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var canTextLabel: UILabel!
@IBOutlet weak var pinTextLabel: UILabel!
@IBOutlet weak var canTextErrorLabel: UILabel!
@IBOutlet weak var canTextInfoLabel: ScaledLabel!
@IBOutlet weak var pinTextErrorLabel: UILabel!
@IBOutlet weak var cancelButton: MoppButton!
@IBOutlet weak var signButton: MoppButton!
Expand All @@ -56,8 +56,8 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning {
pinTextLabel.text = L(.pin2TextfieldLabel)
pinTextLabel.isHidden = notAvailable

canTextErrorLabel.text = ""
canTextErrorLabel.isHidden = true
setCANDefaultText()

pinTextErrorLabel.text = ""
pinTextErrorLabel.isHidden = true

Expand All @@ -84,6 +84,20 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning {
tapGR.addTarget(self, action: #selector(cancelAction))
view.addGestureRecognizer(tapGR)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if let canNumber = canTextField.text {
if !canNumber.isEmpty && canNumber.count != 6 {
setCANErrorText()
} else {
setCANDefaultText()
}
} else {
setCANDefaultText()
}
}

@objc func dismissKeyboard(_ notification: NSNotification) {
pinTextField.resignFirstResponder()
Expand Down Expand Up @@ -196,6 +210,18 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning {
override func keyboardWillHide(notification: NSNotification) {
hideKeyboard(scrollView: scrollView)
}

func setCANDefaultText() {
canTextInfoLabel.text = L(.nfcCanLocation)
canTextInfoLabel.isHidden = false
canTextInfoLabel.textColor = UIColor.moppText
}

func setCANErrorText() {
canTextInfoLabel.text = L(.nfcIncorrectLength)
canTextInfoLabel.isHidden = false
canTextInfoLabel.textColor = UIColor.moppError
}
}

extension NFCEditViewController : UITextFieldDelegate {
Expand Down Expand Up @@ -226,12 +252,17 @@ extension NFCEditViewController : UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
if textField.accessibilityIdentifier == "nfcCanField" {
if let can = textField.text {
if !can.isEmpty && can.count != 6 {
setCANErrorText()
} else {
setCANDefaultText()
}
do {
let symKey = try EncryptedDataUtil.getSymmetricKey(fileName: NFCEditViewController.nfcCANKeyFilename)
if let encryptedKey = EncryptedDataUtil.encryptSecret(can, with: symKey) {
_ = KeychainUtil.save(key: NFCEditViewController.nfcCANKey, info: encryptedKey, withPasscodeSetOnly: true)
} else {
printLog("Encryption failed for 'can' string")
printLog("Encryption failed for 'CAN' string")
}
} catch {
do {
Expand All @@ -249,8 +280,7 @@ extension NFCEditViewController : UITextFieldDelegate {
}
} else {
KeychainUtil.remove(key: NFCEditViewController.nfcCANKey)
canTextErrorLabel.text = ""
canTextErrorLabel.isHidden = true
setCANDefaultText()
removeViewBorder(view: textField)
UIAccessibility.post(notification: .layoutChanged, argument: canTextField)
}
Expand Down
18 changes: 9 additions & 9 deletions MoppApp/MoppApp/TokenFlow.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -1418,7 +1418,7 @@
<rect key="frame" x="0.0" y="20" width="343" height="390"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mnI-M7-BHK">
<rect key="frame" x="0.0" y="0.0" width="343" height="385.5"/>
<rect key="frame" x="0.0" y="0.0" width="343" height="393.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="253" text="Enter your card CAN and PIN2 to sign with ID-card" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rjC-XY-qFD" customClass="ScaledLabel" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="32" y="16" width="279" height="44.5"/>
Expand Down Expand Up @@ -1458,11 +1458,11 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Invalid card access number" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="afX-4g-ZPX" customClass="ScaledLabel" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="25" y="154.5" width="293" height="15.5"/>
<fontDescription key="fontDescription" name="Roboto-Regular" family="Roboto" pointSize="13"/>
<color key="textColor" name="MoppError"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Enter PIN2" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MZs-mQ-MWX" customClass="ScaledLabel" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="25" y="186" width="293" height="15.5"/>
<rect key="frame" x="25" y="194" width="293" height="15.5"/>
<accessibility key="accessibilityConfiguration">
<bool key="isElement" value="NO"/>
</accessibility>
Expand All @@ -1471,7 +1471,7 @@
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="DQo-E7-fVV" customClass="MyTextField" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="25" y="209" width="293" height="46"/>
<rect key="frame" x="25" y="217" width="293" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration" identifier="nfcPinField"/>
<constraints>
Expand All @@ -1490,13 +1490,13 @@
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Invalid PIN code" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6h2-T5-xe7" customClass="ScaledLabel" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="25" y="263" width="293" height="15.5"/>
<rect key="frame" x="25" y="271" width="293" height="15.5"/>
<fontDescription key="fontDescription" name="Roboto-Regular" family="Roboto" pointSize="13"/>
<color key="textColor" name="MoppError"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="0hb-jd-IP1">
<rect key="frame" x="25" y="303.5" width="293" height="32"/>
<rect key="frame" x="25" y="311.5" width="293" height="32"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ydU-Wj-AnM" customClass="ScaledButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="144" height="32"/>
Expand Down Expand Up @@ -1547,7 +1547,7 @@
<constraint firstAttribute="trailing" secondItem="MZs-mQ-MWX" secondAttribute="trailing" constant="25" id="LX2-yJ-ISj"/>
<constraint firstItem="DQo-E7-fVV" firstAttribute="top" secondItem="MZs-mQ-MWX" secondAttribute="bottom" constant="7.5" id="M4i-Tu-clC"/>
<constraint firstAttribute="trailing" secondItem="6h2-T5-xe7" secondAttribute="trailing" constant="25" id="Moo-iA-C8z"/>
<constraint firstItem="MZs-mQ-MWX" firstAttribute="top" secondItem="afX-4g-ZPX" secondAttribute="bottom" constant="16" id="NTa-4U-NtB"/>
<constraint firstItem="MZs-mQ-MWX" firstAttribute="top" secondItem="afX-4g-ZPX" secondAttribute="bottom" constant="24" id="NTa-4U-NtB"/>
<constraint firstItem="rjC-XY-qFD" firstAttribute="leading" secondItem="mnI-M7-BHK" secondAttribute="leading" constant="32" id="RDz-al-lt6"/>
<constraint firstAttribute="trailing" secondItem="rjC-XY-qFD" secondAttribute="trailing" constant="32" id="aUN-rk-ffR"/>
<constraint firstAttribute="trailing" secondItem="pCt-vy-MdB" secondAttribute="trailing" constant="25" id="cQD-Ql-OdU"/>
Expand Down Expand Up @@ -1598,8 +1598,8 @@
</view>
<size key="freeformSize" width="343" height="410"/>
<connections>
<outlet property="canTextErrorLabel" destination="afX-4g-ZPX" id="HPg-94-4te"/>
<outlet property="canTextField" destination="nLi-7a-MsG" id="QVm-Z8-jGl"/>
<outlet property="canTextInfoLabel" destination="afX-4g-ZPX" id="WjX-bQ-759"/>
<outlet property="canTextLabel" destination="pCt-vy-MdB" id="x05-tb-OSS"/>
<outlet property="cancelButton" destination="ydU-Wj-AnM" id="FZv-2h-1mi"/>
<outlet property="pinTextErrorLabel" destination="6h2-T5-xe7" id="1Jb-wb-A6j"/>
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@
"nfc-title" = "Enter your ID-card access number and PIN2 code to sign with ID-card";
"nfc-can-title" = "ID-card access number";
"nfc-device-no-support" = "This device does not support NFC.";
"nfc-can-location" = "The 6-digit access number of the ID card is located under the document photo";
"nfc-incorrect-length" = "CAN-code must be 6 digits long";
"nfc-hold-near" = "Hold your phone near the ID-card";
"nfc-multiple-cards" = "More than 1 NFC tag is detected, please remove all NFC tags and try again";
"nfc-invalid-tag" = "Invalid NFC tag";
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/et.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
"nfc-title" = "ID-kaardiga allkirjastamiseks sisesta oma ID-kaardi ligipääsu number ja PIN2-kood";
"nfc-can-title" = "ID-kaardi ligipääsu number";
"nfc-device-no-support" = "See seade ei toeta NFC-d";
"nfc-can-location" = "ID-kaardi 6-kohaline ligipääsu number asub dokumendi foto all";
"nfc-incorrect-length" = "Ligipääsu number (CAN) peab olema 6-kohaline";
"nfc-hold-near" = "Hoidke ID-kaarti telefoni lähedal";
"nfc-multiple-cards" = "Rohkem kui 1 NFC märgis on tuvastatud, eemaldage kõik NFC-märgisega esemed ja proovige uuesti";
"nfc-invalid-tag" = "Kehtetu NFC-märgis";
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
"nfc-title" = "Введите номер доступа к карте и PIN2-код для подписи с помощью ID-карты";
"nfc-can-title" = "Номер доступа к карте";
"nfc-device-no-support" = "Это устройство не поддерживает NFC";
"nfc-can-location" = "6-значный номер находится под фотографией на документе";
"nfc-incorrect-length" = "Номер доступа (CAN) должен состоять из %1$s-цифр";
"nfc-hold-near" = "Держите телефон рядом с ID-картой";
"nfc-multiple-cards" = "Обнаружено более одной NFC-метки, пожалуйста, удалите все NFC-метки и повторите попытку";
"nfc-invalid-tag" = "Недействительная NFC-метка";
Expand Down

0 comments on commit eb946f7

Please sign in to comment.