Gregniuki commited on
Commit
c5c3f8a
1 Parent(s): 44372ef

Update auth.py

Browse files
Files changed (1) hide show
  1. auth.py +3 -19
auth.py CHANGED
@@ -2,8 +2,8 @@
2
  from fastapi import Depends, HTTPException, Form, Response, status
3
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
4
  from fastapi.templating import Jinja2Templates
5
- from fastapi.responses import HTMLResponse
6
- from fastapi.requests import Request
7
  from pydantic import BaseModel
8
  from sqlalchemy.orm import Session
9
  from models import User
@@ -92,7 +92,7 @@ def create_access_token(self, data: dict, expires_delta: timedelta):
92
  return encoded_jwt
93
 
94
  # Your login route
95
- @app.post("/auth/login", response_model=dict)
96
  def login(self, form_data: OAuth2PasswordRequestForm = Depends()):
97
  # Check email verification
98
  db_user = database.get_user_by_email(db, form_data.username)
@@ -115,19 +115,3 @@ auth_views = AuthViews()
115
 
116
 
117
 
118
- # User authentication (protected route)
119
- @app.get("/protected", response_model=str)
120
- async def protected_route(self,request: Request, token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)):
121
- # Verify the access token
122
- user = verify_token(token, self.SECRET_KEY, self.ALGORITHM)
123
- if user is None:
124
- raise HTTPException(status_code=401, detail="Invalid or expired token")
125
-
126
- # Check if the user exists in the database
127
- db_user = get_user_by_email(db, user) # Modify this to match your database query
128
-
129
- if db_user is None:
130
- raise HTTPException(status_code=401, detail="User not found in the database")
131
-
132
- # The user exists in the database, and you can render the protected route template
133
- return templates.TemplateResponse("protected.html", {"request": request, "user": db_user.username})
 
2
  from fastapi import Depends, HTTPException, Form, Response, status
3
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
4
  from fastapi.templating import Jinja2Templates
5
+ #from fastapi.responses import HTMLResponse
6
+ #from fastapi.requests import Request
7
  from pydantic import BaseModel
8
  from sqlalchemy.orm import Session
9
  from models import User
 
92
  return encoded_jwt
93
 
94
  # Your login route
95
+ #@app.post("/auth/login", response_model=dict)
96
  def login(self, form_data: OAuth2PasswordRequestForm = Depends()):
97
  # Check email verification
98
  db_user = database.get_user_by_email(db, form_data.username)
 
115
 
116
 
117