Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Authentication Service Model and Views #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jinja2==3.1.3
pyyaml==6.0.1
pytest
types-requests
passlib
2 changes: 2 additions & 0 deletions src/data/database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Any, Generator
from sqlmodel import SQLModel, create_engine, Session
from sqlalchemy_utils import database_exists, create_database
from sqlalchemy.ext.declarative import declarative_base
import constants

Base = declarative_base()

def create_tables(db_engine) -> None:
from models.turnilo_dashboard import TurniloDashboard
Expand Down
14 changes: 14 additions & 0 deletions src/models/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sqlalchemy import Column, Integer, String, Boolean

from data.database import Base


class User(Base):
__tablename__ = "users"

id = Column(Integer, primary_key=True, index=True)
tenant_id = Column(Integer, index=True) # Not sure about this one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see DH being multi-tenant anytime soon. I would see RBAC fit the bill for most of the things, so I would add Roles"

Having said that, leave it. JIC.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will make it nullable and optional so it does not slowdown the implementation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm.. Name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And username

Copy link
Author

@OscarMoya OscarMoya Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, bear in mind that there are some providers (oAuth) that they don't have any name, just the email . This is OK as emails are unique and you don't need additional unique constrains on the DB. That being said, if you want we can do it optional and if not provided use the email as user-name

email = Column(String, unique=True, index=True)
hashed_password = Column(String)
is_active = Column(Boolean, default=True)
oauth_provider = Column(String, default=None)
Empty file added src/services/authentication.py
Empty file.
Empty file added src/views/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions src/views/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pydantic import BaseModel
from passlib.context import CryptContext

from models.authentication import User as UserModel

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


def get_password_hash(password) -> str:
return pwd_context.hash(password)


class UserRequest(BaseModel):
email: str
password: str

def to_model(self, tenant_id: int, oauth_provider: str) -> UserModel:
return UserModel(
tenant_id=tenant_id,
email=self.email,
hashed_password=get_password_hash(self.password), # TODO: Interline gibberish for extra protection
oauth_provider=oauth_provider,
)


Loading