add endpoint for create
This commit is contained in:
parent
97554069b5
commit
3c58a1361c
|
@ -59,7 +59,6 @@ func Handler(
|
|||
r: r,
|
||||
al: al,
|
||||
}
|
||||
|
||||
mux.HandleFunc("/members", r.HTML("admin/allow-list.tmpl", ah.overview))
|
||||
mux.HandleFunc("/members/add", ah.add)
|
||||
mux.HandleFunc("/members/remove/confirm", r.HTML("admin/allow-list-remove-confirm.tmpl", ah.removeConfirm))
|
||||
|
@ -69,8 +68,8 @@ func Handler(
|
|||
r: r,
|
||||
db: is,
|
||||
}
|
||||
|
||||
mux.HandleFunc("/invites", r.HTML("admin/invites.tmpl", ih.overview))
|
||||
mux.HandleFunc("/invites/create", ih.create)
|
||||
|
||||
var nh = noticeHandler{
|
||||
r: r,
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"go.mindeco.de/http/render"
|
||||
|
||||
"github.com/gorilla/csrf"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/admindb"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/web/user"
|
||||
)
|
||||
|
||||
type invitesH struct {
|
||||
|
@ -35,3 +37,29 @@ func (h invitesH) overview(rw http.ResponseWriter, req *http.Request) (interface
|
|||
|
||||
return pageData, nil
|
||||
}
|
||||
|
||||
func (h invitesH) create(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "POST" {
|
||||
// TODO: proper error type
|
||||
h.r.Error(w, req, http.StatusBadRequest, fmt.Errorf("bad request"))
|
||||
return
|
||||
}
|
||||
if err := req.ParseForm(); err != nil {
|
||||
// TODO: proper error type
|
||||
h.r.Error(w, req, http.StatusBadRequest, fmt.Errorf("bad request: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
aliasSuggestion := req.Form.Get("alias_suggestion")
|
||||
|
||||
token, err := h.db.Create(req.Context(), user.ID, aliasSuggestion)
|
||||
if err != nil {
|
||||
h.r.Error(w, req, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("use me:", token)
|
||||
|
||||
http.Redirect(w, req, "/admin/invites", http.StatusFound)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue