39 lines
1 KiB
Go
39 lines
1 KiB
Go
|
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)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|