feat(webui): add user account delete
All checks were successful
main / main (push) Successful in 1m46s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped

Closes #19
This commit is contained in:
Julien Dessaux 2025-05-05 00:34:08 +02:00
parent 373f567773
commit 8d75b75af7
Signed by: adyxax
GPG key ID: F92E51B86E07177E
6 changed files with 57 additions and 20 deletions

View file

@ -91,8 +91,25 @@ func handleAccountsIdPOST(db *database.DB) http.Handler {
action := r.FormValue("action")
switch action {
case "delete":
errorResponse(w, r, http.StatusNotImplemented, nil)
return
if !page.Account.Deleted {
page.Account.MarkForDeletion()
success, err := db.SaveAccount(page.Account)
if err != nil {
errorResponse(w, r, http.StatusInternalServerError,
fmt.Errorf("failed to save account: %w", err))
return
}
if !success {
errorResponse(w, r, http.StatusInternalServerError,
fmt.Errorf("failed to save account: this cannot happen"))
return
}
if err := db.DeleteSessions(page.Account); err != nil {
errorResponse(w, r, http.StatusInternalServerError,
fmt.Errorf("failed to delete sessions: %w", err))
return
}
}
case "edit":
page.Username = r.FormValue("username")
isAdmin := r.FormValue("is-admin")
@ -119,8 +136,13 @@ func handleAccountsIdPOST(db *database.DB) http.Handler {
return
}
case "reset-password":
if page.Account.Deleted {
errorResponse(w, r, http.StatusBadRequest,
fmt.Errorf("You cannot reset the password for this account because it is marked for deletion."))
return
}
if err := page.Account.ResetPassword(); err != nil {
errorResponse(w, r, http.StatusNotImplemented,
errorResponse(w, r, http.StatusInternalServerError,
fmt.Errorf("failed to reset password: %w", err))
return
}
@ -137,7 +159,7 @@ func handleAccountsIdPOST(db *database.DB) http.Handler {
}
if err := db.DeleteSessions(page.Account); err != nil {
errorResponse(w, r, http.StatusInternalServerError,
fmt.Errorf("failed to save account: %w", err))
fmt.Errorf("failed to delete sessions: %w", err))
return
}
default: