-
Notifications
You must be signed in to change notification settings - Fork 929
/
passwd_command.go
60 lines (45 loc) · 1.17 KB
/
passwd_command.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
58
59
60
package v7
import (
"code.cloudfoundry.org/cli/command/translatableerror"
)
type PasswdCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME passwd"`
}
func (cmd PasswdCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
currentUser, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
currentPassword, err := cmd.UI.DisplayPasswordPrompt("Current password")
if err != nil {
return err
}
newPassword, err := cmd.UI.DisplayPasswordPrompt("New password")
if err != nil {
return err
}
verifyPassword, err := cmd.UI.DisplayPasswordPrompt("Verify password")
if err != nil {
return err
}
cmd.UI.DisplayNewline()
cmd.UI.DisplayTextWithFlavor("Changing password for user {{.Username}}...", map[string]interface{}{
"Username": currentUser.Name,
})
if newPassword != verifyPassword {
return translatableerror.PasswordVerificationFailedError{}
}
err = cmd.Actor.UpdateUserPassword(currentUser.GUID, currentPassword, newPassword)
if err != nil {
return err
}
cmd.UI.DisplayOK()
cmd.Config.UnsetUserInformation()
cmd.UI.DisplayText("Please log in again.")
return nil
}