Merge branch 'bensbits' into ext-boltcards-2

This commit is contained in:
ben 2022-08-27 17:26:28 +01:00
commit 77ecc5a1d2
2 changed files with 17 additions and 18 deletions

View file

@ -33,7 +33,7 @@ from .crud import (
create_hit, create_hit,
get_card, get_card,
get_card_by_otp, get_card_by_otp,
get_card_by_uid, get_card,
get_hit, get_hit,
get_hits_today, get_hits_today,
spend_hit, spend_hit,
@ -47,8 +47,8 @@ from .nxp424 import decryptSUN, getSunMAC
###############LNURLWITHDRAW################# ###############LNURLWITHDRAW#################
# /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000 # /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000
@boltcards_ext.get("/api/v1/scan/{card_uid}") @boltcards_ext.get("/api/v1/scan/{card_id}")
async def api_scan(p, c, request: Request, card_uid: str = None): async def api_scan(p, c, request: Request, card_id: str = None):
# some wallets send everything as lower case, no bueno # some wallets send everything as lower case, no bueno
p = p.upper() p = p.upper()
c = c.upper() c = c.upper()
@ -66,7 +66,7 @@ async def api_scan(p, c, request: Request, card_uid: str = None):
if card == None: if card == None:
return {"status": "ERROR", "reason": "Unknown card."} return {"status": "ERROR", "reason": "Unknown card."}
if c != getSunMAC(card_uid, counter, bytes.fromhex(card.k2)).hex().upper(): if c != getSunMAC(card_id, counter, bytes.fromhex(card.k2)).hex().upper():
return {"status": "ERROR", "reason": "CMAC does not check."} return {"status": "ERROR", "reason": "CMAC does not check."}
ctr_int = int.from_bytes(counter, "little") ctr_int = int.from_bytes(counter, "little")

View file

@ -9,6 +9,7 @@ const mapCards = obj => {
return obj return obj
} }
new Vue({ new Vue({
el: '#vue', el: '#vue',
mixins: [windowMixin], mixins: [windowMixin],
@ -18,7 +19,6 @@ new Vue({
cards: [], cards: [],
hits: [], hits: [],
refunds: [], refunds: [],
lnurlLink: location.hostname + '/boltcards/api/v1/scan/',
cardDialog: { cardDialog: {
show: false, show: false,
data: { data: {
@ -44,10 +44,10 @@ new Vue({
field: 'counter' field: 'counter'
}, },
{ {
name: 'uid', name: 'withdraw',
align: 'left', align: 'left',
label: 'Card ID', label: 'Withdraw ID',
field: 'uid' field: 'withdraw'
} }
], ],
pagination: { pagination: {
@ -66,7 +66,7 @@ new Vue({
name: 'refund_amount', name: 'refund_amount',
align: 'left', align: 'left',
label: 'Refund Amount', label: 'Refund Amount',
field: 'oldrefund_amount_ctr' field: 'refund_amount'
}, },
{ {
name: 'time', name: 'time',
@ -140,13 +140,12 @@ new Vue({
.request( .request(
'GET', 'GET',
'/boltcards/api/v1/cards?all_wallets=true', '/boltcards/api/v1/cards?all_wallets=true',
this.g.user.wallets[0].adminkey this.g.user.wallets[0].inkey
) )
.then(function (response) { .then(function (response) {
self.cards = response.data.map(function (obj) { self.cards = response.data.map(function (obj) {
return mapCards(obj) return mapCards(obj)
}) })
console.log(self.cards)
}) })
}, },
getHits: function () { getHits: function () {
@ -162,7 +161,6 @@ new Vue({
obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name
return mapCards(obj) return mapCards(obj)
}) })
console.log(self.hits)
}) })
}, },
getRefunds: function () { getRefunds: function () {
@ -175,10 +173,8 @@ new Vue({
) )
.then(function (response) { .then(function (response) {
self.refunds = response.data.map(function (obj) { self.refunds = response.data.map(function (obj) {
obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name
return mapCards(obj) return mapCards(obj)
}) })
console.log(self.hits)
}) })
}, },
openQrCodeDialog(cardId) { openQrCodeDialog(cardId) {
@ -252,7 +248,6 @@ new Vue({
}, },
updateCardDialog: function (formId) { updateCardDialog: function (formId) {
var card = _.findWhere(this.cards, {id: formId}) var card = _.findWhere(this.cards, {id: formId})
console.log(card.id)
this.cardDialog.data = _.clone(card) this.cardDialog.data = _.clone(card)
this.cardDialog.temp.k0 = this.cardDialog.data.k0 this.cardDialog.temp.k0 = this.cardDialog.data.k0
@ -274,8 +269,6 @@ new Vue({
data.prev_k2 = this.cardDialog.temp.k2 data.prev_k2 = this.cardDialog.temp.k2
} }
console.log(data)
LNbits.api LNbits.api
.request( .request(
'PUT', 'PUT',
@ -320,7 +313,13 @@ new Vue({
}, },
exportCardsCSV: function () { exportCardsCSV: function () {
LNbits.utils.exportCSV(this.cardsTable.columns, this.cards) LNbits.utils.exportCSV(this.cardsTable.columns, this.cards)
} },
exportHitsCSV: function () {
LNbits.utils.exportCSV(this.hitsTable.columns, this.hits)
},
exportRefundsCSV: function () {
LNbits.utils.exportCSV(this.refundsTable.columns, this.refunds)
},
}, },
created: function () { created: function () {
if (this.g.user.wallets.length) { if (this.g.user.wallets.length) {