Use v1 for verify
This commit is contained in:
parent
cc0326d93a
commit
b58dd9ed6d
1 changed files with 26 additions and 16 deletions
|
@ -16,13 +16,16 @@
|
||||||
package verify
|
package verify
|
||||||
|
|
||||||
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 (
|
||||||
|
@ -36,23 +39,30 @@ 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.VerifyRequest{
|
||||||
Type: "verify",
|
Account: args[0],
|
||||||
ID: requestID,
|
|
||||||
Username: args[0],
|
|
||||||
Code: args[1],
|
Code: args[1],
|
||||||
})
|
}
|
||||||
|
resp, err := req.Submit(common.Signald)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("error sending request to signald: ", err)
|
log.Fatal("error sending request to signald: ", err)
|
||||||
}
|
}
|
||||||
c := make(chan v0.LegacyResponse)
|
switch common.OutputFormat {
|
||||||
go common.Signald.Listen(c)
|
case common.OutputFormatJSON:
|
||||||
response := signald.GetLegacyResponse(c, requestID)
|
err := json.NewEncoder(os.Stdout).Encode(resp)
|
||||||
if response.Type == "verification_succeeded" {
|
if err != nil {
|
||||||
log.Println("verification succeeded")
|
log.Fatal(err, "error encoding response to stdout")
|
||||||
} else {
|
}
|
||||||
log.Fatalf("unexpected response from signald when requesting verification code: %+v", response)
|
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("verification succeeded")
|
||||||
|
default:
|
||||||
|
log.Fatal("Unsupported output format")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue