This file contains hidden or 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
# To assure reproducability, the given Redis database (db=0) | |
# !!! is CLEARED !!! each time the application starts | |
# | |
# $ export JWT_SECRET=something | |
# $ python3 -m pip install flask pyjwt redis | |
# $ export REDIS_PASSWORD=verycomplex | |
# $ export REDIS_PORT=6379 | |
# $ export REDIS_HOST=myhost.com | |
from os import getenv | |
from flask import Flask, g |
This file contains hidden or 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
# $ export JWT_SECRET=something | |
# $ python3 -m pip install pyjwt | |
import jwt, os | |
import datetime | |
SECRET = os.getenv("JWT_SECRET") | |
NOW = datetime.datetime.now(tz=datetime.timezone.utc) | |
def user_token(uid, role, seconds=60): | |
dt = datetime.timedelta(seconds=seconds) |
This file contains hidden or 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
from flask import Flask | |
from flask import request | |
from flask import make_response | |
from json import loads, dumps | |
import random, string | |
app = Flask(__name__) | |
carts = { # server-side application state | |
'deadbeef' : {'Marchewka' : 4} |
This file contains hidden or 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
from flask import Flask | |
from flask import request | |
from flask import make_response | |
from json import loads, dumps | |
app = Flask(__name__) | |
@app.route("/add2cart", methods=["POST"]) | |
def add2cart(): | |
cart = {} # default value, can be loaded from cookies | |
cookies = request.headers.get("Cookie", "") |
NewerOlder