Implement user authentication and permissions
This commit is contained in:
parent
5e9d90ed0b
commit
ac8303378a
26 changed files with 1182 additions and 172 deletions
|
@ -4,6 +4,7 @@ __all__ = [
|
|||
"connector",
|
||||
"id_token",
|
||||
"meter_value",
|
||||
"session",
|
||||
"transaction",
|
||||
"user"
|
||||
]
|
14
app/models/session.py
Normal file
14
app/models/session.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import uuid
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String, Uuid
|
||||
|
||||
from app.database import Base
|
||||
|
||||
class Session(Base):
|
||||
__tablename__ = "sessions"
|
||||
|
||||
id = Column(Uuid, primary_key=True, default=uuid.uuid4)
|
||||
name = Column(String)
|
||||
refresh_token = Column(String, unique=True, index=True)
|
||||
last_used = Column(DateTime(timezone=True))
|
||||
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), index=True)
|
|
@ -1,15 +1,19 @@
|
|||
import uuid
|
||||
from sqlalchemy import Uuid, Boolean, Column, String
|
||||
from sqlalchemy import Enum, Uuid, Boolean, Column, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
from app.schemas.user import Role
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Uuid, primary_key=True, default=uuid.uuid4)
|
||||
friendly_name = Column(String, unique=True, index=True)
|
||||
is_active = Column(Boolean, default=True)
|
||||
friendly_name = Column(String, nullable=True)
|
||||
is_active = Column(Boolean, nullable=False, default=True)
|
||||
email = Column(String, nullable=False, unique=True, index=True)
|
||||
password = Column(String, nullable=False)
|
||||
role = Column(Enum(Role), nullable=False, default=Role.MEMBER)
|
||||
|
||||
id_tokens = relationship("IdToken", back_populates="owner", cascade="delete, delete-orphan")
|
||||
transactions = relationship("Transaction", cascade="delete, delete-orphan")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue