Spaces:
Sleeping
Sleeping
up
Browse files- admin.py +9 -0
- database.db +0 -0
- templates/admin.html +10 -0
admin.py
CHANGED
|
@@ -152,6 +152,8 @@ async def edit_user(
|
|
| 152 |
email: str = Form(...),
|
| 153 |
is_admin: bool = Form(False),
|
| 154 |
is_active: bool = Form(False),
|
|
|
|
|
|
|
| 155 |
db: Session = Depends(get_db),
|
| 156 |
):
|
| 157 |
current_user = login_required(request, db)
|
|
@@ -168,10 +170,17 @@ async def edit_user(
|
|
| 168 |
and db.query(User).filter(User.username == new_username).first()
|
| 169 |
):
|
| 170 |
raise HTTPException(status_code=400, detail="Username already exists")
|
|
|
|
| 171 |
user.username = new_username
|
| 172 |
user.email = email
|
| 173 |
user.is_admin = is_admin
|
| 174 |
user.is_active = is_active
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
db.commit()
|
| 176 |
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 177 |
|
|
|
|
| 152 |
email: str = Form(...),
|
| 153 |
is_admin: bool = Form(False),
|
| 154 |
is_active: bool = Form(False),
|
| 155 |
+
old_password: str = Form(None),
|
| 156 |
+
new_password: str = Form(None),
|
| 157 |
db: Session = Depends(get_db),
|
| 158 |
):
|
| 159 |
current_user = login_required(request, db)
|
|
|
|
| 170 |
and db.query(User).filter(User.username == new_username).first()
|
| 171 |
):
|
| 172 |
raise HTTPException(status_code=400, detail="Username already exists")
|
| 173 |
+
|
| 174 |
user.username = new_username
|
| 175 |
user.email = email
|
| 176 |
user.is_admin = is_admin
|
| 177 |
user.is_active = is_active
|
| 178 |
+
|
| 179 |
+
if old_password and new_password:
|
| 180 |
+
if user.password != old_password:
|
| 181 |
+
raise HTTPException(status_code=400, detail="Incorrect old password")
|
| 182 |
+
user.password = new_password
|
| 183 |
+
|
| 184 |
db.commit()
|
| 185 |
return RedirectResponse(url="/admin", status_code=status.HTTP_302_FOUND)
|
| 186 |
|
database.db
CHANGED
|
Binary files a/database.db and b/database.db differ
|
|
|
templates/admin.html
CHANGED
|
@@ -204,6 +204,14 @@
|
|
| 204 |
<input type="checkbox" class="form-check-input" id="editIsActive" name="is_active" value="true">
|
| 205 |
<label class="form-check-label" for="editIsActive">Is Active</label>
|
| 206 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
</div>
|
| 208 |
<div class="modal-footer">
|
| 209 |
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
@@ -330,6 +338,8 @@
|
|
| 330 |
document.getElementById('editEmail').value = email;
|
| 331 |
document.getElementById('editIsAdmin').checked = isAdmin;
|
| 332 |
document.getElementById('editIsActive').checked = isActive;
|
|
|
|
|
|
|
| 333 |
var editUserModal = new bootstrap.Modal(document.getElementById('editUserModal'));
|
| 334 |
editUserModal.show();
|
| 335 |
}
|
|
|
|
| 204 |
<input type="checkbox" class="form-check-input" id="editIsActive" name="is_active" value="true">
|
| 205 |
<label class="form-check-label" for="editIsActive">Is Active</label>
|
| 206 |
</div>
|
| 207 |
+
<div class="mb-3">
|
| 208 |
+
<label for="editOldPassword" class="form-label">Old Password</label>
|
| 209 |
+
<input type="password" class="form-control" id="editOldPassword" name="old_password">
|
| 210 |
+
</div>
|
| 211 |
+
<div class="mb-3">
|
| 212 |
+
<label for="editNewPassword" class="form-label">New Password</label>
|
| 213 |
+
<input type="password" class="form-control" id="editNewPassword" name="new_password">
|
| 214 |
+
</div>
|
| 215 |
</div>
|
| 216 |
<div class="modal-footer">
|
| 217 |
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
|
|
| 338 |
document.getElementById('editEmail').value = email;
|
| 339 |
document.getElementById('editIsAdmin').checked = isAdmin;
|
| 340 |
document.getElementById('editIsActive').checked = isActive;
|
| 341 |
+
document.getElementById('editOldPassword').value = '';
|
| 342 |
+
document.getElementById('editNewPassword').value = '';
|
| 343 |
var editUserModal = new bootstrap.Modal(document.getElementById('editUserModal'));
|
| 344 |
editUserModal.show();
|
| 345 |
}
|