Update main.py
Browse files
main.py
CHANGED
@@ -50,17 +50,21 @@ async def login_post(
|
|
50 |
|
51 |
# Check user authentication (You should implement this function)
|
52 |
user = authenticate_user(db, email, password)
|
53 |
-
|
54 |
-
if user:
|
55 |
# Authentication succeeded
|
56 |
-
#
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
else:
|
61 |
# Authentication failed
|
62 |
-
#
|
63 |
-
return RedirectResponse("/login?error=Authentication failed")
|
64 |
|
65 |
@app.get("/register", response_class=HTMLResponse)
|
66 |
async def register_get(request: Request):
|
|
|
50 |
|
51 |
# Check user authentication (You should implement this function)
|
52 |
user = authenticate_user(db, email, password)
|
53 |
+
|
54 |
+
if user is not None:
|
55 |
# Authentication succeeded
|
56 |
+
# Create an access token and handle login success
|
57 |
+
# You can use your access token creation logic here
|
58 |
+
access_token = auth_views().create_access_token(
|
59 |
+
data={"sub": user.email},
|
60 |
+
expires_delta=timedelta(minutes=auth_views().ACCESS_TOKEN_EXPIRE_MINUTES),
|
61 |
+
)
|
62 |
+
# Redirect to a protected page or handle the login success as needed
|
63 |
+
return RedirectResponse("/protected")
|
64 |
else:
|
65 |
# Authentication failed
|
66 |
+
# Handle login failure, e.g., display an error message
|
67 |
+
return templates.TemplateResponse("login.html", {"request": request, "error_message": "Invalid email or password"}) return RedirectResponse("/login?error=Authentication failed")
|
68 |
|
69 |
@app.get("/register", response_class=HTMLResponse)
|
70 |
async def register_get(request: Request):
|