Skip to content

Commit f8261d7

Browse files
committed
Add submenu and icons for debug functionality, move admin pages into main sidedraw, reuse lachlans password change dialog
1 parent 7ff2cf6 commit f8261d7

File tree

10 files changed

+991
-458
lines changed

10 files changed

+991
-458
lines changed

adminui/structs.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ type LogLinesDTO struct {
2626
}
2727

2828
type ChangePasswordRequestDTO struct {
29-
CurrentPassword string
30-
NewPassword string
29+
CurrentPassword string `json:"current_password"`
30+
NewPassword string `json:"new_password"`
3131
}
3232

3333
type RegistrationTokenRequestDTO struct {
@@ -38,11 +38,6 @@ type RegistrationTokenRequestDTO struct {
3838
Uses int
3939
}
4040

41-
type ChangePasswordResponseDTO struct {
42-
Message string
43-
Type int
44-
}
45-
4641
type UsersData struct {
4742
Username string `json:"username"`
4843
Devices int `json:"devices"`

adminui/ui_webserver.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -477,40 +477,33 @@ func (au *AdminUI) changePassword(w http.ResponseWriter, r *http.Request) {
477477
return
478478
}
479479

480-
var d ChangePasswordResponseDTO
481-
d.Type = 0
482-
d.Message = "Success!"
483-
484-
defer func() {
485-
w.Header().Set("content-type", "application/json")
486-
json.NewEncoder(w).Encode(d)
487-
}()
480+
var (
481+
err error
482+
)
483+
defer func() { au.respond(err, w) }()
488484

489485
var req ChangePasswordRequestDTO
490-
err := json.NewDecoder(r.Body).Decode(&r)
486+
err = json.NewDecoder(r.Body).Decode(&r)
491487
r.Body.Close()
492488
if err != nil {
493-
d.Message = "Failed"
494-
d.Type = 1
495-
489+
w.WriteHeader(http.StatusBadRequest)
496490
return
497491
}
498492

499493
err = data.CompareAdminKeys(u.Username, req.CurrentPassword)
500494
if err != nil {
501495
log.Println("bad password for admin")
502-
503-
d.Message = "Current password is incorrect"
504-
d.Type = 1
496+
err = errors.New("current password is incorrect")
497+
w.WriteHeader(http.StatusUnauthorized)
505498
return
506499
}
507500

508501
err = data.SetAdminPassword(u.Username, req.NewPassword)
509502
if err != nil {
510503
log.Println("unable to set new admin password for ", u.Username)
511504

512-
d.Message = "Error: " + err.Error()
513-
d.Type = 1
505+
err = fmt.Errorf("error setting password: %w", err)
506+
w.WriteHeader(http.StatusInternalServerError)
514507
return
515508
}
516509

0 commit comments

Comments
 (0)