fix: do not allow two merchants with the same public key

This commit is contained in:
Vlad Stan 2023-03-16 09:56:30 +02:00
parent b2f5f519c3
commit 3794eac915
3 changed files with 13 additions and 6 deletions

View file

@ -342,8 +342,9 @@ async function customerStall(path) {
let json = JSON.parse(text) let json = JSON.parse(text)
if (json.id != this.activeOrder) return if (json.id != this.activeOrder) return
if (json.payment_options) { if (json.payment_options) {
let payment_request = json.payment_options.find(o => o.type == 'ln') let payment_request = json.payment_options.find(
.link o => o.type == 'ln'
).link
if (!payment_request) return if (!payment_request) return
this.loading = false this.loading = false
this.qrCodeDialog.data.payment_request = payment_request this.qrCodeDialog.data.payment_request = payment_request

View file

@ -78,10 +78,7 @@ const merchant = async () => {
message: 'Merchant Created!' message: 'Merchant Created!'
}) })
} catch (error) { } catch (error) {
this.$q.notify({ LNbits.utils.notifyApiError(error)
type: 'negative',
message: `${error}`
})
} }
}, },
getMerchant: async function () { getMerchant: async function () {

View file

@ -32,6 +32,7 @@ from .crud import (
delete_stall, delete_stall,
delete_zone, delete_zone,
get_direct_messages, get_direct_messages,
get_merchant_by_pubkey,
get_merchant_for_user, get_merchant_for_user,
get_order, get_order,
get_orders, get_orders,
@ -78,6 +79,9 @@ async def api_create_merchant(
) -> Merchant: ) -> Merchant:
try: try:
merchant = await get_merchant_by_pubkey(data.public_key)
assert merchant == None, "A merchant already uses this public key"
merchant = await get_merchant_for_user(wallet.wallet.user) merchant = await get_merchant_for_user(wallet.wallet.user)
assert merchant == None, "A merchant already exists for this user" assert merchant == None, "A merchant already exists for this user"
@ -85,6 +89,11 @@ async def api_create_merchant(
await subscribe_to_direct_messages(data.public_key, 0) await subscribe_to_direct_messages(data.public_key, 0)
return merchant return merchant
except AssertionError as ex:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=str(ex),
)
except Exception as ex: except Exception as ex:
logger.warning(ex) logger.warning(ex)
raise HTTPException( raise HTTPException(