mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
I've split everything in different concepts (groups, login, products and delivery) so that it's easier to find what we're looking for (the __init__.py file was really too big).
37 lines
768 B
Python
37 lines
768 B
Python
from datetime import datetime, timezone, timedelta
|
|
|
|
import jwt
|
|
|
|
from . import config
|
|
|
|
|
|
def utcnow():
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
def create_token(email):
|
|
return jwt.encode(
|
|
{"sub": str(email), "exp": utcnow() + timedelta(days=7)},
|
|
config.SECRET,
|
|
config.JWT_ALGORITHM,
|
|
)
|
|
|
|
|
|
def read_token(token):
|
|
try:
|
|
return jwt.decode(token, config.SECRET, algorithms=[config.JWT_ALGORITHM])
|
|
except (jwt.DecodeError, jwt.ExpiredSignatureError):
|
|
return {}
|
|
|
|
|
|
def prefix(string, delivery):
|
|
date = delivery.to_date.strftime("%Y-%m-%d")
|
|
return f"{config.SITE_NAME}-{date}-{string}"
|
|
|
|
|
|
def date_filter(value):
|
|
return value.strftime(r"%A %d %B")
|
|
|
|
|
|
def time_filter(value):
|
|
return value.strftime(r"%H:%M")
|