-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frontend app linked with basic ui connected to backend api and ma…
…intaining user session through public_key
- Loading branch information
1 parent
10e91bc
commit 3d02857
Showing
39 changed files
with
29,806 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from art_factory import generate_unique_nft | ||
from flask import Flask, request, make_response, jsonify, current_app | ||
from flask_cors import CORS | ||
from functools import wraps | ||
from ipfs import upload | ||
from blockchain import create_account | ||
from datetime import datetime, timedelta | ||
import jwt | ||
|
||
# nft = generate_unique_nft() | ||
# response = upload(nft) | ||
# print(response) | ||
|
||
app = Flask(__name__) | ||
app.config["APP_SECRET"] = "KSiJ65bGtapUEQeg" | ||
app.config["DEBUG"] = True | ||
CORS(app, origins=["http://localhost:3000"], supports_credentials = True) | ||
|
||
|
||
@app.route('/auth', methods=['POST']) | ||
def signup(): | ||
post_data = request.get_json(force=True) | ||
private_key = None | ||
if post_data and "private_key" in post_data: | ||
private_key = post_data["private_key"] | ||
if private_key: | ||
public_key = create_account(private_key = private_key) | ||
response = {'status': 'success', 'message':'Account created successfully', "key": public_key} | ||
response = make_response(jsonify(response), 200) | ||
response.set_cookie("public_key", value=public_key, httponly=True, samesite="None", secure=True) | ||
else: | ||
public_key, private_key = create_account(private_key = private_key) | ||
response = {'status': 'success', 'message':'Account loaded successfully', "key": {'public': public_key, 'private': private_key}} | ||
response = make_response(jsonify(response), 200) | ||
response.set_cookie("public_key", value=public_key, httponly=True, samesite="None", secure=True) | ||
return response | ||
|
||
|
||
@app.route('/refresh_session') | ||
def refresh_token(): | ||
if request.cookies and "public_key" in request.cookies: | ||
public_key = request.cookies.get("public_key") | ||
response = {'status': 'success', 'message':'Admin signin successful','user': public_key} | ||
response = make_response(jsonify(response), 200) | ||
else: | ||
response = {'status': 'error', 'message': 'Authentication failed'} | ||
response = make_response(jsonify(response), 400) | ||
|
||
return response | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
from web3 import Web3 | ||
|
||
network_url= "HTTP://127.0.0.1:7545" | ||
web3 = Web3(Web3.HTTPProvider(network_url)) | ||
contract_address = "" | ||
contract_abi = '' | ||
|
||
def create_account(private_key = None): | ||
if private_key: | ||
acct = web3.eth.account.privateKeyToAccount(private_key) | ||
print(acct) | ||
return acct.address | ||
else: | ||
account = web3.eth.account.create() | ||
return account.address, web3.toHex(account.privateKey) | ||
|
||
def send_eth(to_account, amount): | ||
from_account = web3.eth.accounts[0] | ||
|
||
tx = { | ||
"nonce": web3.eth.get_transaction_count(from_account), | ||
"to": to_account, | ||
"value": web3.toWei(amount, "ether"), | ||
"gas": 2000000, | ||
"gasPrice": web3.toWei(50, "gwei") | ||
} | ||
|
||
signed_tx = web3.eth.account.sign_transaction(tx, "ea34a23473fa895af810ec354474fef923686007242f510883a18d93028a04d6") | ||
|
||
try: | ||
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction) | ||
tx_response = web3.eth.get_transaction_receipt(tx_hash) | ||
|
||
if tx_response and tx_response["status"] == 1: | ||
return True, None | ||
else: | ||
return False, "Something wrong happened" | ||
|
||
except Exception as e: | ||
return False, e["message"] | ||
|
||
def format_address(address): | ||
return web3.toChecksumAddress(address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
Empty file.
Oops, something went wrong.