signaldctl: Use v1 request type for register so errors (especially captcha errors) are shown to the user
Probably shouldn't have closed #10 before this
This commit is contained in:
parent
3005802e5c
commit
4e1603db2e
2 changed files with 30 additions and 21 deletions
|
@ -16,13 +16,16 @@
|
||||||
package register
|
package register
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||||
"gitlab.com/signald/signald-go/signald"
|
v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||||
"gitlab.com/signald/signald-go/signald/client-protocol/v0"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -39,27 +42,32 @@ var (
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
requestID := signald.GenerateID()
|
go common.Signald.Listen(nil)
|
||||||
err := common.Signald.RawRequest(v0.LegacyRequest{
|
req := v1.RegisterRequest{
|
||||||
Type: "register",
|
Account: args[0],
|
||||||
ID: requestID,
|
Voice: voice,
|
||||||
Username: args[0],
|
Captcha: captcha,
|
||||||
Voice: voice,
|
|
||||||
Captcha: captcha,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("error sending request to signald: ", err)
|
|
||||||
}
|
}
|
||||||
c := make(chan v0.LegacyResponse)
|
resp, err := req.Submit(common.Signald)
|
||||||
go common.Signald.Listen(c)
|
if err != nil {
|
||||||
response := signald.GetLegacyResponse(c, requestID)
|
log.Fatal("error: ", err)
|
||||||
switch response.Type {
|
}
|
||||||
case "verification_required":
|
|
||||||
log.Println("verification code requested. submit with: signaldctl account verify", args[0], "<code>")
|
switch common.OutputFormat {
|
||||||
case "captcha_required":
|
case common.OutputFormatJSON:
|
||||||
log.Println("captcha required. Please provide a captcha token with the --captcha argument (see https://gitlab.com/signald/signald/-/wikis/Captchas)")
|
err := json.NewEncoder(os.Stdout).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err, "error encoding response to stdout")
|
||||||
|
}
|
||||||
|
case common.OutputFormatYAML:
|
||||||
|
err := yaml.NewEncoder(os.Stdout).Encode(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err, "error encoding response to stdout")
|
||||||
|
}
|
||||||
|
case common.OutputFormatDefault:
|
||||||
|
fmt.Println("submit verification code with signaldctl account verify ", resp.AccountId, "000000")
|
||||||
default:
|
default:
|
||||||
log.Fatalf("unexpected response from signald when requesting verification code: %+v", response)
|
log.Fatal("Unsupported output format")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -76,6 +76,7 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
|
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
|
||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
|
|
Loading…
Reference in a new issue