-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: Authentication Service Model and Views
- Loading branch information
Showing
6 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ jinja2==3.1.3 | |
pyyaml==6.0.1 | ||
pytest | ||
types-requests | ||
passlib |
This file contains 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
This file contains 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
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 | ||
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.
Empty file.
This file contains 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
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, | ||
) | ||
|
||
|