github.com/decred/politeia@v1.4.0/politeiawww/cmd/shared/usertotpset.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  // UserTOTPSetCmd sets the TOTP key for the logged in user.
    14  type UserTOTPSetCmd struct {
    15  	Args struct {
    16  		Code string `positional-arg-name:"code"`
    17  	} `positional-args:"true"`
    18  }
    19  
    20  // Execute executes the set totp command.
    21  func (cmd *UserTOTPSetCmd) Execute(args []string) error {
    22  	// Setup new user request
    23  	st := &v1.SetTOTP{
    24  		Code: cmd.Args.Code,
    25  		Type: 1,
    26  	}
    27  
    28  	// Print request details
    29  	err := PrintJSON(st)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	// Send request
    35  	str, err := client.SetTOTP(st)
    36  	if err != nil {
    37  		return fmt.Errorf("SetTOTP: %v", err)
    38  	}
    39  
    40  	// Print response details
    41  	err = PrintJSON(str)
    42  	if err != nil {
    43  		return err
    44  	}
    45  
    46  	return nil
    47  }