Gregniuki commited on
Commit
bda9eb4
·
1 Parent(s): 7e59b23

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -8
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
- # Generate an access token (You should implement this function)
57
- access_token = create_access_token(user.email)
58
- # Redirect to a protected route with the access token
59
- return RedirectResponse("/protected?token=" + access_token)
 
 
 
 
60
  else:
61
  # Authentication failed
62
- # You can redirect back to the login page with an error message
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):