Update app.py
Browse files
app.py
CHANGED
@@ -259,6 +259,9 @@ async def verify_email(token: str, db: Session = Depends(get_db)):
|
|
259 |
response.set_cookie(key="access_token", value=f"Bearer {access_token}", httponly=True, secure=True, samesite='Lax')
|
260 |
return response
|
261 |
|
|
|
|
|
|
|
262 |
@app.get("/register", response_class=HTMLResponse)
|
263 |
async def register_get(request: Request):
|
264 |
return templates.TemplateResponse("register.html", {"request": request, "google_oauth_url": request.url_for("login_oauth")})
|
@@ -280,6 +283,8 @@ async def register_post(
|
|
280 |
return templates.TemplateResponse("register.html", {"request": request, "error_message": "Passwords do not match."})
|
281 |
|
282 |
user_data = UserCreate(username=username, email=email, password=password)
|
|
|
|
|
283 |
try:
|
284 |
registered_user = register_user(user_data, db)
|
285 |
# Store user info in the session after successful registration
|
|
|
259 |
response.set_cookie(key="access_token", value=f"Bearer {access_token}", httponly=True, secure=True, samesite='Lax')
|
260 |
return response
|
261 |
|
262 |
+
def is_username_available(db: Session, username: str) -> bool:
|
263 |
+
return db.query(User).filter(User.username == username).first() is None
|
264 |
+
|
265 |
@app.get("/register", response_class=HTMLResponse)
|
266 |
async def register_get(request: Request):
|
267 |
return templates.TemplateResponse("register.html", {"request": request, "google_oauth_url": request.url_for("login_oauth")})
|
|
|
283 |
return templates.TemplateResponse("register.html", {"request": request, "error_message": "Passwords do not match."})
|
284 |
|
285 |
user_data = UserCreate(username=username, email=email, password=password)
|
286 |
+
if not is_username_available(db, user_data.username):
|
287 |
+
raise HTTPException(status_code=400, detail="Username already taken")
|
288 |
try:
|
289 |
registered_user = register_user(user_data, db)
|
290 |
# Store user info in the session after successful registration
|