Add session model, use utc_now utility

This commit is contained in:
2024-11-07 11:32:24 -06:00
parent 95b05e077a
commit d612625de8
2 changed files with 20 additions and 3 deletions
+1
View File
@@ -1,6 +1,7 @@
{ {
"cSpell.words": [ "cSpell.words": [
"apscheduler", "apscheduler",
"backref",
"bpython", "bpython",
"Callsite", "Callsite",
"excepthook", "excepthook",
+19 -3
View File
@@ -7,9 +7,11 @@ from datetime import datetime
from os import getenv from os import getenv
import structlog import structlog
from peewee import CharField, DateTimeField, IntegerField, AutoField, Model from peewee import AutoField, CharField, DateTimeField, ForeignKeyField, Model
from playhouse.db_url import connect from playhouse.db_url import connect
from linkpulse.utilities import utc_now
logger = structlog.get_logger() logger = structlog.get_logger()
@@ -33,5 +35,19 @@ class User(BaseModel):
email = CharField(unique=True, max_length=45) email = CharField(unique=True, max_length=45)
# full hash with encoded salt/parameters, argon2 but assume nothing # full hash with encoded salt/parameters, argon2 but assume nothing
password_hash = CharField(max_length=96) password_hash = CharField(max_length=96)
created_at = DateTimeField(default=datetime.now) created_at = DateTimeField(default=utc_now)
updated_at = DateTimeField(default=datetime.now) updated_at = DateTimeField(default=utc_now)
class Session(BaseModel):
"""
A session represents a user's login session.
"""
token = CharField(unique=True, primary_key=True, max_length=32)
user = ForeignKeyField(User, backref="sessions")
expiry = DateTimeField()
created_at = DateTimeField(default=utc_now)
last_used = DateTimeField(null=True)