Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70792

QR code validation

$
0
0

@IonC wrote:

I am developing an Ionic 4 app that should scan and validate QR code for claiming, using PhoneGap Plugin BarcodeScanner. The scanning is working as expected but I’m having difficulties on validating the QR code.

My idea is that the QR code is only valid for the user if the userID and PromotionID matches the QR Code (in Firestore database). I’m using the document ID’s to generate QR code For example, QR code ’ 075u6SGzsZ3tWq1v3Trb ’ and ’ XXDzN47QXqsGZIMeySw0 ’ can only be use by user123.


Below is the implementation

Example.page.ts:

qr: any;

scanQRCode () {
  this.options= {
  preferFrontCamera : false, 
  showFlipCameraButton : true, 
  showTorchButton:true,
  disableSuccessBeep: false,
  torchOn: false,
  prompt: 'Scan your QRcode'
};
this.subscription = this.afs.collection('claims')
 .snapshotChanges()
 .subscribe(data => {

  this.qr= data.map(e => {
    return {
      id: e.payload.doc.id,
      promotionID: e.payload.doc.data()['promotion'],
      userID: e.payload.doc.data()['user'],
    };
  })
  console.log(this.item);
  this.subscription.unsubscribe();
});

    this.scanner.scan(this.options).then((data) => {
      this.scannedData = data;
      if(this.qr.promotionID && this.qr.userID == data){
      this.navCtrl.navigateForward('/nextPage');
    }else{
      return this.presentAlert('Error','Invalid QRCODE')
    }

  }, (err) => {
  console.log('Error: ',err);
 })
}

Example.page.html

<ion-button expand="block" icon-left (click)="scanQRCode()"><ion-icon name="qr-scanner"></ion-icon>Scan code</ion-button>

I need help. Please be gentle since I am new to Ionic and Firebase. Thank you.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70792

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>