Fixed user input to read a complete line when creating users

This commit is contained in:
Magnus Åhall 2024-01-26 07:57:32 +01:00
parent 7c5eaa74d9
commit 3b778226c8

10
pkg.go
View File

@ -38,6 +38,7 @@ import (
"git.gibonuddevalla.se/go/webservice/ws_conn_manager"
// Standard
"bufio"
"embed"
"encoding/json"
"errors"
@ -234,13 +235,16 @@ func (service *Service) CreateUser(username, password, name string) (err error)
func (service *Service) CreateUserPrompt() { // {{{
var err error
var username, name, password string
reader := bufio.NewReader(os.Stdin)
fmt.Printf("Username: ")
fmt.Scanln(&username)
username, _ = reader.ReadString('\n')
fmt.Printf("Name: ")
fmt.Scanln(&name)
name, _ = reader.ReadString('\n')
fmt.Printf("Password: ")
fmt.Scanln(&password)
password, _ = reader.ReadString('\n')
err = service.CreateUser(username, password, name)
if err != nil {