diff --git a/database.go b/database.go index b2c612c..cca7171 100644 --- a/database.go +++ b/database.go @@ -57,7 +57,7 @@ func AddNewUser(ctx context.Context, user User) (uint32, error) { INSERT INTO users (Name, PassHash, Color) VALUES ($1, $2, $3) RETURNING Id - `, user.Name, user.IsPasswordHashed, user.Color).Scan(&id) + `, user.Name, user.Password, user.Color).Scan(&id) return id, err } diff --git a/go-socket b/go-socket index 9b84457..13b2a7a 100755 Binary files a/go-socket and b/go-socket differ diff --git a/http.go b/http.go index 57304ab..2f10170 100644 --- a/http.go +++ b/http.go @@ -1,6 +1,7 @@ package main import ( + "log" "net/http" "golang.org/x/crypto/bcrypt" @@ -30,6 +31,14 @@ func RegisterHandler(response http.ResponseWriter, request *http.Request) { } if _, err := AddNewUser(ctx, User{0, username, password, "xxx", false}); err != nil { + http.Error(response, "Internal server error", http.StatusInternalServerError) + log.Fatal(err) + return + } + + response.WriteHeader(http.StatusCreated) + _, err := response.Write([]byte("registered")) + if err != nil { http.Error(response, "Internal server error", http.StatusInternalServerError) return } diff --git a/machine-client/index.html b/machine-client/index.html new file mode 100644 index 0000000..01cdde3 --- /dev/null +++ b/machine-client/index.html @@ -0,0 +1,151 @@ + + +
+ +curl -X POST localhost:8080/register -d "username=alice&password=password123"curl -X POST localhost:8080/login -d "username=alice&password=password123"
+