Skip to content

Commit

Permalink
Fix new account creation error due to hardcoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtyped committed Nov 28, 2022
1 parent b1bcf40 commit 3eaf882
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/accounts_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -29,7 +30,8 @@ var accountsCreateCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
username := args[0]
// make apiAddr separate it out into username/port
val := url.Values{"username": {username}, "password": {"password"}, "email": {email}, "name": {name}}

val := url.Values{"username": {username}, "password": {password}, "email": {email}, "name": {name}}

addr := fmt.Sprintf("http://%s/api/internal/users", apiAddr)
res, err := http.PostForm(addr, val)
Expand All @@ -39,7 +41,9 @@ var accountsCreateCmd = &cobra.Command{
}

if res.StatusCode != 201 {
log.Println("Could not create status code")
body, _ := ioutil.ReadAll(res.Body)
log.Printf("Could not create user: %s", string(body))
return
}

log.Printf("😍 User %s created!", username)
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (u *UserAPI) HandleUserCreate(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Printf("error adding user: %#v", err)
w.WriteHeader(400)
w.Write([]byte(err.Error()))
return
}

Expand Down

0 comments on commit 3eaf882

Please sign in to comment.