very rough updates to admin pages, reduced reliance on global.DB
This commit is contained in:
parent
ae254dd731
commit
7044f7344b
15 changed files with 192 additions and 106 deletions
38
admin/accounthttp.go
Normal file
38
admin/accounthttp.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
func AccountHandler(db *sqlx.DB) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
account := r.Context().Value("account").(*model.Account)
|
||||
|
||||
totps, err := controller.GetTOTPsForAccount(db, account.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch TOTPs: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
type AccountResponse struct {
|
||||
Account *model.Account
|
||||
TOTPs []model.TOTP
|
||||
}
|
||||
|
||||
err = pages["account"].Execute(w, AccountResponse{
|
||||
Account: account,
|
||||
TOTPs: totps,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to render admin account page: %v\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue