27 lines
579 B
Go
27 lines
579 B
Go
package site
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"ruben/inventory2/internal/site/response"
|
|
)
|
|
|
|
// POST /accounts
|
|
func (s *Server) createAccount(r *http.Request) (response.Response, error) {
|
|
ctx := r.Context()
|
|
email := r.FormValue("email")
|
|
if email == "" {
|
|
return nil, response.BadRequest().Msg("no email provided")
|
|
}
|
|
|
|
userID := getAccessTokenClaims(ctx).Subject
|
|
|
|
acct, err := s.accts.CreateAccount(ctx, userID, email)
|
|
if err != nil {
|
|
return nil, response.Errorf("failed to create account: %w", err)
|
|
}
|
|
|
|
return response.SeeOther(fmt.Sprintf("/accounts/%d", acct.ID)), nil
|
|
}
|