github.com/decred/politeia@v1.4.0/politeiawww/cmd/shared/usertotpverify.go (about) 1 // Copyright (c) 2017-2019 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package shared 6 7 import ( 8 "fmt" 9 10 v1 "github.com/decred/politeia/politeiawww/api/www/v1" 11 ) 12 13 // UserTOTPVerifyCmd verifies the TOTP key for the logged in user. 14 type UserTOTPVerifyCmd struct { 15 Args struct { 16 Code string `positional-arg-name:"code"` 17 } `positional-args:"true"` 18 } 19 20 // Execute executes the verify totp command. 21 func (cmd *UserTOTPVerifyCmd) Execute(args []string) error { 22 // Setup new user request 23 st := &v1.VerifyTOTP{ 24 Code: cmd.Args.Code, 25 } 26 27 // Print request details 28 err := PrintJSON(st) 29 if err != nil { 30 return err 31 } 32 33 // Send request 34 str, err := client.VerifyTOTP(st) 35 if err != nil { 36 return fmt.Errorf("VerifyTOTP: %v", err) 37 } 38 39 // Print response details 40 err = PrintJSON(str) 41 if err != nil { 42 return err 43 } 44 45 return nil 46 }