Spaces:
Sleeping
Sleeping
Add login required
Browse files
app.py
CHANGED
|
@@ -159,34 +159,6 @@ async def edit_user(request: Request, username: str, new_username: str = Form(..
|
|
| 159 |
save_users()
|
| 160 |
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 161 |
|
| 162 |
-
@app.post("/admin/delete/{username}")
|
| 163 |
-
async def delete_user(username: str, current_user: User = Depends(get_current_user)):
|
| 164 |
-
if not current_user.is_admin:
|
| 165 |
-
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Not authorized")
|
| 166 |
-
global users
|
| 167 |
-
users = [u for u in users if u.username != username]
|
| 168 |
-
save_users()
|
| 169 |
-
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 170 |
-
|
| 171 |
-
@app.post("/admin/edit/{username}")
|
| 172 |
-
async def edit_user(request: Request, username: str, new_username: str = Form(...), email: str = Form(...), is_admin: bool = Form(False), is_active: bool = Form(False)):
|
| 173 |
-
current_user = login_required(request)
|
| 174 |
-
if isinstance(current_user, RedirectResponse):
|
| 175 |
-
return current_user
|
| 176 |
-
if not current_user.is_admin:
|
| 177 |
-
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Not authorized")
|
| 178 |
-
user = next((u for u in users if u.username == username), None)
|
| 179 |
-
if user:
|
| 180 |
-
# Check if the new username already exists
|
| 181 |
-
if new_username != username and any(u.username == new_username for u in users):
|
| 182 |
-
raise HTTPException(status_code=400, detail="Username already exists")
|
| 183 |
-
user.username = new_username
|
| 184 |
-
user.email = email
|
| 185 |
-
user.is_admin = is_admin
|
| 186 |
-
user.is_active = is_active
|
| 187 |
-
save_users()
|
| 188 |
-
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 189 |
-
|
| 190 |
@app.post("/api/generate-data")
|
| 191 |
def generate_data():
|
| 192 |
base_latitude = 35.6837
|
|
|
|
| 159 |
save_users()
|
| 160 |
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
@app.post("/api/generate-data")
|
| 163 |
def generate_data():
|
| 164 |
base_latitude = 35.6837
|