mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-20 10:39:59 +01:00
checks before creating new subdomain
This commit is contained in:
parent
dc4a786dda
commit
33b48341f1
@ -4,8 +4,6 @@ from lnbits.helpers import urlsafe_short_hash
|
|||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import Domains, Subdomains
|
from .models import Domains, Subdomains
|
||||||
import httpx
|
|
||||||
|
|
||||||
from lnbits.extensions import subdomains
|
from lnbits.extensions import subdomains
|
||||||
|
|
||||||
|
|
||||||
@ -73,6 +71,14 @@ async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]:
|
|||||||
print(row)
|
print(row)
|
||||||
return Subdomains(**row) if row else None
|
return Subdomains(**row) if row else None
|
||||||
|
|
||||||
|
async def get_subdomainBySubdomain(subdomain: str) -> Optional[Subdomains]:
|
||||||
|
row = await db.fetchone(
|
||||||
|
"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.subdomain = ?",
|
||||||
|
(subdomain, ),
|
||||||
|
)
|
||||||
|
print(row)
|
||||||
|
return Subdomains(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_subdomains(wallet_ids: Union[str, List[str]]) -> List[Subdomains]:
|
async def get_subdomains(wallet_ids: Union[str, List[str]]) -> List[Subdomains]:
|
||||||
if isinstance(wallet_ids, str):
|
if isinstance(wallet_ids, str):
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
from lnbits.extensions.subdomains.models import Subdomains
|
from lnbits.extensions.subdomains.models import Subdomains
|
||||||
import trio # type: ignore
|
|
||||||
import json
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
# Python3 program to validate
|
# Python3 program to validate
|
||||||
# domain name
|
# domain name
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from quart import g, jsonify, request
|
from quart import g, jsonify, request
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
from lnbits.core import crud
|
||||||
|
|
||||||
from lnbits.core.crud import get_user, get_wallet
|
from lnbits.core.crud import get_user, get_wallet
|
||||||
from lnbits.core.services import create_invoice, check_invoice_status
|
from lnbits.core.services import create_invoice, check_invoice_status
|
||||||
@ -18,6 +19,7 @@ from .crud import (
|
|||||||
get_domain,
|
get_domain,
|
||||||
get_domains,
|
get_domains,
|
||||||
delete_domain,
|
delete_domain,
|
||||||
|
get_subdomainBySubdomain
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -117,9 +119,16 @@ async def api_subdomain_make_subdomain(domain_id):
|
|||||||
return jsonify({"message": g.data["ip"] + " Not a valid IP address"}), HTTPStatus.BAD_REQUEST
|
return jsonify({"message": g.data["ip"] + " Not a valid IP address"}), HTTPStatus.BAD_REQUEST
|
||||||
if not isValidDomain(g.data["subdomain"] + "." + domain.domain):
|
if not isValidDomain(g.data["subdomain"] + "." + domain.domain):
|
||||||
return (
|
return (
|
||||||
jsonify({"message": g.data["subdomain"] + "." + domain.domain + " Bad domain name"}),
|
jsonify({"message": g.data["subdomain"] + "." + domain.domain + " bad domain name"}),
|
||||||
HTTPStatus.BAD_REQUEST,
|
HTTPStatus.BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ( await get_subdomainBySubdomain(g.data["subdomain"]) is not None):
|
||||||
|
return (
|
||||||
|
jsonify({"message": g.data["subdomain"] + "." + domain.domain + " domain already taken"}),
|
||||||
|
HTTPStatus.BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
if g.data["record_type"] not in domain.allowed_record_types:
|
if g.data["record_type"] not in domain.allowed_record_types:
|
||||||
return jsonify({"message": g.data["record_type"] + "Not a valid record"}), HTTPStatus.BAD_REQUEST
|
return jsonify({"message": g.data["record_type"] + "Not a valid record"}), HTTPStatus.BAD_REQUEST
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user