diff --git a/account.py b/account.py index 52ddcb8..f43fc95 100644 --- a/account.py +++ b/account.py @@ -27,9 +27,6 @@ def check_account(cookie: str): return False account = cookie.split(":")[0] - password = ":".join(cookie.split(":")[1:]) - - # Check if the account is valid info = hsw.getAccountInfo(account, 'default') if 'error' in info: @@ -66,10 +63,9 @@ def getAddress(account: str): def getPendingTX(account: str): # Get the pending transactions - info = hsw.getWalletTxHistory() + info = hsw.getWalletTxHistory(account) if 'error' in info: return 0 - pending = 0 for tx in info: if tx['confirmations'] < 1: @@ -77,7 +73,6 @@ def getPendingTX(account: str): return pending - def getDomains(account): # Get the domains # info = hsw.getWalletNames(account) @@ -182,4 +177,25 @@ def getDomain(domain: str): return { "error": response['error']['message'] } - return response['result'] \ No newline at end of file + return response['result'] + +def renewDomain(account,domain): + account_name = check_account(account) + password = ":".join(account.split(":")[1:]) + + if account_name == False: + return { + "error": "Invalid account" + } + + response = hsw.sendRENEW(account_name,password,domain) + return response + +def getDNS(domain: str): + # Get the DNS + response = hsd.rpc_getNameResource(domain) + if response['error'] is not None: + return { + "error": response['error']['message'] + } + return response['result']['records'] diff --git a/main.py b/main.py index 1b3555d..ff8a6e1 100644 --- a/main.py +++ b/main.py @@ -218,18 +218,54 @@ def search(): dns = render.dns(dns) txs = render.txs(txs) - - - - return render_template("search.html", account=account, search_term=search_term, domain=domain['info']['name'],raw=domain, state=state, next=next, owner=owner, dns=dns, txs=txs) +@app.route('/manage/') +def manage(domain): + # Check if the user is logged in + if request.cookies.get("account") is None: + return redirect("/login") + account = account_module.check_account(request.cookies.get("account")) + if not account: + return redirect("/logout") + + domain = domain.lower() + + own_domains = account_module.getDomains(account) + own_domains = [x['name'] for x in own_domains] + own_domains = [x.lower() for x in own_domains] + if domain not in own_domains: + return redirect("/search?q=" + domain) + + domain_info = account_module.getDomain(domain) + if 'error' in domain_info: + return render_template("manage.html", account=account, domain=domain, error=domain_info['error']) + + expiry = domain_info['info']['stats']['daysUntilExpire'] + dns = account_module.getDNS(domain) + dns = render.dns(dns) + + + return render_template("manage.html", account=account, domain=domain, + expiry=expiry, dns=dns) + + +@app.route('/manage//renew') +def renew(domain): + # Check if the user is logged in + if request.cookies.get("account") is None: + return redirect("/login") - + if not account_module.check_account(request.cookies.get("account")): + return redirect("/logout") + + domain = domain.lower() + response = account_module.renewDomain(request.cookies.get("account"),domain) + return redirect("/success?tx=" + response['hash']) #endregion diff --git a/templates/404.html b/templates/404.html index 41b47fc..47d9aaa 100644 --- a/templates/404.html +++ b/templates/404.html @@ -39,7 +39,7 @@