From 83cf9efc94037f8730034c7d81d7f7215288cad2 Mon Sep 17 00:00:00 2001 From: Finn Date: Sun, 14 Mar 2021 16:16:04 -0700 Subject: [PATCH] Add captcha support to register command captcha_required detection doesn't work unfortunately, as the captcha required message doesn't unmarshal due to the "data" field being a string --- .../cmd/account/register/register-account.go | 12 +++++++++--- signald/client-protocol/v0/signaldrequest.go | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/signaldctl/cmd/account/register/register-account.go b/cmd/signaldctl/cmd/account/register/register-account.go index f97504d..b2c92c0 100644 --- a/cmd/signaldctl/cmd/account/register/register-account.go +++ b/cmd/signaldctl/cmd/account/register/register-account.go @@ -26,7 +26,8 @@ import ( ) var ( - voice bool + voice bool + captcha string RegisterAccountCmd = &cobra.Command{ Use: "register [phone number]", @@ -44,6 +45,7 @@ var ( ID: requestID, Username: args[0], Voice: voice, + Captcha: captcha, }) if err != nil { log.Fatal("error sending request to signald: ", err) @@ -51,9 +53,12 @@ var ( c := make(chan v0.LegacyResponse) go common.Signald.Listen(c) response := signald.GetLegacyResponse(c, requestID) - if response.Type == "verification_required" { + switch response.Type { + case "verification_required": log.Println("verification code requested. submit with: signaldctl account verify", args[0], "") - } else { + case "captcha_required": + log.Println("captcha required. Please provide a captcha token with the --captcha argument (see https://gitlab.com/signald/signald/-/wikis/Captchas)") + default: log.Fatalf("unexpected response from signald when requesting verification code: %+v", response) } }, @@ -62,4 +67,5 @@ var ( func init() { RegisterAccountCmd.Flags().BoolVarP(&voice, "voice", "V", false, "request verification code be sent via an automated voice call (code is sent via SMS by default)") + RegisterAccountCmd.Flags().StringVarP(&captcha, "captcha", "c", "", "a captcha token may be required to register, see https://gitlab.com/signald/signald/-/wikis/Captchas for how to get one") } diff --git a/signald/client-protocol/v0/signaldrequest.go b/signald/client-protocol/v0/signaldrequest.go index d087387..a695cd3 100644 --- a/signald/client-protocol/v0/signaldrequest.go +++ b/signald/client-protocol/v0/signaldrequest.go @@ -21,7 +21,7 @@ type LegacyRequest struct { ID string `json:"id,omitempty"` Username string `json:"username,omitempty"` MessageBody string `json:"messageBody,omitempty"` - RecipientAddress JsonAddress `json:"recipientAddress,omitempty"` + RecipientAddress *JsonAddress `json:"recipientAddress,omitempty"` RecipientGroupID string `json:"recipientGroupId,omitempty"` Voice bool `json:"voice,omitempty"` Code string `json:"code,omitempty"` @@ -32,6 +32,7 @@ type LegacyRequest struct { GroupName string `json:"groupName,omitempty"` Members []string `json:"members,omitempty"` Avatar string `json:"avatar,omitempty"` + Captcha string `json:"captcha,omitempty"` } type JsonAddress struct {