feat
This commit is contained in:
parent
ce16d4ea1b
commit
978cadf11b
24
main.ipynb
24
main.ipynb
@ -4219,6 +4219,30 @@
|
||||
],
|
||||
"display_name": ".venv"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c7c3772b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@app.post(\"/api/admin/delete-user\")\n",
|
||||
"async def delete_user(\n",
|
||||
" payload: DeleteUserRequest,\n",
|
||||
" user: Dict = Security(get_current_user, scopes=[\"admin\"]),\n",
|
||||
"):\n",
|
||||
" try:\n",
|
||||
" result = users_collection.delete_one({\"_id\": ObjectId(payload._id)})\n",
|
||||
" except Exception:\n",
|
||||
" raise HTTPException(status_code=400, detail=\"Неверный ID пользователя\")\n",
|
||||
"\n",
|
||||
" if result.deleted_count == 0:\n",
|
||||
" raise HTTPException(status_code=404, detail=\"Пользователь не найден\")\n",
|
||||
"\n",
|
||||
" return {\"ok\": True}\n"
|
||||
],
|
||||
"display_name": ".venv"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
16
main.py
16
main.py
@ -3251,6 +3251,22 @@ async def unsubscribe(
|
||||
"""
|
||||
|
||||
|
||||
@app.post("/api/admin/delete-user")
|
||||
async def delete_user(
|
||||
payload: DeleteUserRequest,
|
||||
user: Dict = Security(get_current_user, scopes=["admin"]),
|
||||
):
|
||||
try:
|
||||
result = users_collection.delete_one({"_id": ObjectId(payload._id)})
|
||||
except Exception:
|
||||
raise HTTPException(status_code=400, detail="Неверный ID пользователя")
|
||||
|
||||
if result.deleted_count == 0:
|
||||
raise HTTPException(status_code=404, detail="Пользователь не найден")
|
||||
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.get("/profile/admin/users", response_class=HTMLResponse)
|
||||
async def profile_admin_statistics(
|
||||
request: Request,
|
||||
|
||||
@ -70,6 +70,10 @@ class UserLoginForm(OAuth2PasswordRequestForm):
|
||||
pass
|
||||
|
||||
|
||||
class DeleteUserRequest(BaseModel):
|
||||
_id: str
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
identifier: str
|
||||
password: str
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<th>Телефон</th>
|
||||
<th>Место проживания</th>
|
||||
<th>Дата рождения</th>
|
||||
<th>...</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -54,11 +55,36 @@
|
||||
<td>{{doc.phone or ""}}</td>
|
||||
<td>{{doc.living_place or ""}}</td>
|
||||
<td>{{doc.birthday or ""}}</td>
|
||||
<td><button onclick="deleteUser('{{doc._id}}')">Удалить</button></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
// @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
|
||||
async function deleteUser(params) {
|
||||
try {
|
||||
const res = await fetch('/api/admin/delete-user', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
_id: params,
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
showToast({ message: "Пользователь удален", status: 'success' });
|
||||
} else {
|
||||
showToast({ message: data.detail || "Ошибка", status: 'error' });
|
||||
}
|
||||
} catch (err) {
|
||||
showToast({ message: "Ошибка соединения с сервером", status: 'error' });
|
||||
}
|
||||
}
|
||||
// @license-end
|
||||
</script>
|
||||
<script>
|
||||
// @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
|
||||
function normalizeText(str) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user