Files
inventory-plus-plus/internal/site/accounts.go
T

28 lines
677 B
Go

package site
import (
"fmt"
"net/http"
)
// POST /accounts
func (s *Server) createAccount(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
email := r.FormValue("email")
if email == "" {
http.Error(w, "no email provided", http.StatusBadRequest)
return
}
userID := getAccessTokenClaims(ctx).Subject
acct, err := s.accts.CreateAccount(ctx, userID, email)
if err != nil {
http.Error(w, fmt.Sprintf("failed to create account: %v", err), http.StatusInternalServerError)
return
}
//http.Redirect(w, r, fmt.Sprintf("/site/accounts/%d", acct.ID), http.StatusSeeOther)
http.Redirect(w, r, fmt.Sprintf("/accounts/%d", acct.ID), http.StatusSeeOther)
}