/
changeusername.go
57 lines (45 loc) · 1.42 KB
/
changeusername.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2017-2019 The Fonero developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package commands
import "github.com/fonero-project/politeia/politeiawww/api/www/v1"
// ChangeUsernameCmd changes the username for the logged in user.
type ChangeUsernameCmd struct {
Args struct {
Password string `positional-arg-name:"password"` // User password
NewUsername string `positional-arg-name:"newusername"` // New username
} `positional-args:"true" required:"true"`
}
// Execute executes the change username command.
func (cmd *ChangeUsernameCmd) Execute(args []string) error {
cu := &v1.ChangeUsername{
Password: digestSHA3(cmd.Args.Password),
NewUsername: cmd.Args.NewUsername,
}
// Print request details
err := printJSON(cu)
if err != nil {
return err
}
// Send request
cur, err := client.ChangeUsername(cu)
if err != nil {
return err
}
// Print response details
return printJSON(cur)
}
// changeUsernameHelpMsg is the output of the help command when
// 'changeusername' is specified.
var changeUsernameHelpMsg = `changeusername "password" "newusername"
Change the username for the currently logged in user.
Arguments:
1. password (string, required) Current password
2. newusername (string, required) New username
Request:
{
"password": (string) Current password
"newusername": (string) New username
}
Response:
{}`