Update main.py
Browse files
main.py
CHANGED
@@ -94,9 +94,26 @@ async def register_post(
|
|
94 |
confirm_password: str = Form(...),
|
95 |
db: Session = Depends(get_db)
|
96 |
):
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
|
102 |
@app.post("/registration_successful", response_class=HTMLResponse)
|
|
|
94 |
confirm_password: str = Form(...),
|
95 |
db: Session = Depends(get_db)
|
96 |
):
|
97 |
+
if password != confirm_password:
|
98 |
+
# Return to the registration page with an error
|
99 |
+
return templates.TemplateResponse("register.html", {
|
100 |
+
"request": request,
|
101 |
+
"error_message": "Passwords do not match."
|
102 |
+
})
|
103 |
+
|
104 |
+
try:
|
105 |
+
user = UserCreate(username=username, email=email, password=password, confirm_password=confirm_password)
|
106 |
+
register(user, db) # If this function raises an HTTPException, it should be handled
|
107 |
+
except HTTPException as e:
|
108 |
+
# Return to the registration page with the error detail
|
109 |
+
return templates.TemplateResponse("register.html", {
|
110 |
+
"request": request,
|
111 |
+
"error_message": e.detail
|
112 |
+
})
|
113 |
+
|
114 |
+
# Redirect to the successful registration page
|
115 |
+
response = RedirectResponse("/registration_successful", status_code=status.HTTP_302_FOUND)
|
116 |
+
return response
|
117 |
|
118 |
|
119 |
@app.post("/registration_successful", response_class=HTMLResponse)
|