diff --git a/cmd/signald-cli/cmd/listGroups.go b/cmd/signald-cli/cmd/listGroups.go index d0c8e5f..c40bf49 100644 --- a/cmd/signald-cli/cmd/listGroups.go +++ b/cmd/signald-cli/cmd/listGroups.go @@ -1,4 +1,4 @@ -// Copyright © 2018 Finn Herzfeld +// Copyright © 2020 Finn Herzfeld // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/cmd/signald-cli/cmd/register.go b/cmd/signald-cli/cmd/register.go new file mode 100644 index 0000000..af2f8c5 --- /dev/null +++ b/cmd/signald-cli/cmd/register.go @@ -0,0 +1,58 @@ +// Copyright © 2020 Finn Herzfeld +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package cmd + +import ( + "fmt" + "log" + "math/rand" + + "github.com/spf13/cobra" + + "gitlab.com/signald/signald-go/signald/client-protocol/v0" +) + +// registerCmd represents the register command +var registerCmd = &cobra.Command{ + Use: "register", + Short: "Register a new account.", + Long: `Register a new signal account, generating new keys if the number was previously registered.`, + Run: func(cmd *cobra.Command, args []string) { + requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) + err := s.RawRequest(v0.LegacyRequest{ + Type: "register", + Username: username, + }) + if err != nil { + log.Fatal("error sending request: ", err) + } + go s.Listen(nil) + + r := <-s.GetResponseListener(requestID) + account, err := r.Data.MarshalJSON() + if err != nil { + log.Fatal("error rendering response:", err) + } + fmt.Println("validation code requested. submit the code using signald-cli verify", string(account)) + }, +} + +func init() { + RootCmd.AddCommand(registerCmd) + + registerCmd.Flags().StringVarP(&username, "username", "u", "", "The phone number of the new account to register)") + must(registerCmd.MarkFlagRequired("username")) +} diff --git a/cmd/signald-cli/cmd/verify.go b/cmd/signald-cli/cmd/verify.go new file mode 100644 index 0000000..984fbc1 --- /dev/null +++ b/cmd/signald-cli/cmd/verify.go @@ -0,0 +1,66 @@ +// Copyright © 2020 Finn Herzfeld +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package cmd + +import ( + "fmt" + "log" + "math/rand" + + "github.com/spf13/cobra" + + "gitlab.com/signald/signald-go/signald/client-protocol/v0" +) + +var ( + code string +) + +// verify represents the verify command +var verify = &cobra.Command{ + Use: "verify", + Short: "Verify an account confirmation code and complete account setup", + Long: `Verify the phone number on a new account by submitting a verification code, completing the account registration process.`, + Run: func(cmd *cobra.Command, args []string) { + requestID := fmt.Sprint("signald-cli-", rand.Intn(1000)) + err := s.RawRequest(v0.LegacyRequest{ + Type: "verify", + Username: username, + Code: code, + }) + if err != nil { + log.Fatal("error sending request: ", err) + } + go s.Listen(nil) + + r := <-s.GetResponseListener(requestID) + account, err := r.Data.MarshalJSON() + if err != nil { + log.Fatal("error rendering response:", err) + } + fmt.Println("account created:", string(account)) + }, +} + +func init() { + RootCmd.AddCommand(verify) + + verify.Flags().StringVarP(&username, "username", "u", "", "The phone number the verification code was sent to") + must(verify.MarkFlagRequired("username")) + + verify.Flags().StringVarP(&code, "code", "c", "", "The verification code") + must(verify.MarkFlagRequired("code")) +}