-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
316d23d
commit a387927
Showing
11 changed files
with
74 additions
and
49 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from .auth import router as auth_router | ||
from fastapi import FastAPI | ||
|
||
# Initialize FastAPI | ||
app = FastAPI() | ||
|
||
# Import routes to register them | ||
from .auth import router as auth_router | ||
|
||
# Include the auth router | ||
app.include_router(auth_router, prefix="/api/auth", tags=["auth"]) |
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 |
---|---|---|
@@ -1,24 +1,31 @@ | ||
from app.database import db | ||
from app.models import \ | ||
User # Make sure you have User model defined in models.py | ||
from app.security import create_access_token, verify_password | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm | ||
from sqlalchemy.orm import Session | ||
from app.database import db | ||
from app.models import User # Make sure you have User model defined in models.py | ||
from app.security import verify_password, create_access_token | ||
|
||
router = APIRouter() | ||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") | ||
|
||
|
||
@router.post("/token") | ||
async def login(form_data: OAuth2PasswordRequestForm = Depends()): | ||
user = db.session.query(User).filter(User.username == form_data.username).first() | ||
|
||
user = db.session.query(User).filter( | ||
User.username == form_data.username).first() | ||
|
||
if not user or not verify_password(form_data.password, user.password): | ||
raise HTTPException(status_code=400, detail="Incorrect username or password") | ||
raise HTTPException( | ||
status_code=400, detail="Incorrect username or password") | ||
|
||
access_token = create_access_token(data={"sub": user.username}) | ||
return {"access_token": access_token, "token_type": "bearer"} | ||
|
||
|
||
@router.get("/users/me") | ||
async def read_users_me(token: str = Depends(oauth2_scheme)): | ||
user = db.session.query(User).filter(User.username == token).first() # Add logic to decode token and fetch user | ||
user = ( | ||
db.session.query(User).filter(User.username == token).first() | ||
) # Add logic to decode token and fetch user | ||
return user |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import uvicorn | ||
|
||
from . import app | ||
|
||
if __name__ == "__main__": | ||
|
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
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
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import random | ||
import string | ||
|
||
|
||
def generate_captcha(): | ||
letters = string.ascii_letters | ||
captcha_text = ''.join(random.choice(letters) for i in range(6)) | ||
captcha_text = "".join(random.choice(letters) for i in range(6)) | ||
return captcha_text | ||
|
||
|
||
def verify_captcha(user_input, actual_captcha): | ||
return user_input == actual_captcha |
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