github.com/decred/politeia@v1.4.0/politeiawww/cmd/shared/userusernamechange.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 v1 "github.com/decred/politeia/politeiawww/api/www/v1" 8 9 // UserUsernameChangeCmd changes the username for the logged in user. 10 type UserUsernameChangeCmd struct { 11 Args struct { 12 Password string `positional-arg-name:"password"` // User password 13 NewUsername string `positional-arg-name:"newusername"` // New username 14 } `positional-args:"true" required:"true"` 15 } 16 17 // Execute executes the change username command. 18 func (cmd *UserUsernameChangeCmd) Execute(args []string) error { 19 cu := &v1.ChangeUsername{ 20 Password: DigestSHA3(cmd.Args.Password), 21 NewUsername: cmd.Args.NewUsername, 22 } 23 24 // Print request details 25 err := PrintJSON(cu) 26 if err != nil { 27 return err 28 } 29 30 // Send request 31 cur, err := client.ChangeUsername(cu) 32 if err != nil { 33 return err 34 } 35 36 // Print response details 37 return PrintJSON(cur) 38 } 39 40 // UserUsernameChangeHelpMsg is the output of the help command when 41 // 'userusernamechange' is specified. 42 var UserUsernameChangeHelpMsg = `userusernamechange "password" "newusername" 43 44 Change the username for the currently logged in user. 45 46 Arguments: 47 1. password (string, required) Current password 48 2. newusername (string, required) New username`