@@ -7,9 +7,11 @@ import (
77 "log"
88 "net/url"
99 "os"
10+ "syscall"
1011
1112 "com.lc.go.codepush/client/constants"
1213 "com.lc.go.codepush/client/utils"
14+ "golang.org/x/term"
1315)
1416
1517type User struct {}
@@ -66,6 +68,57 @@ func (User) Login() {
6668 }
6769 log .Println ("Login success" )
6870}
71+
72+ type changePasswordReq struct {
73+ Password * string `json:"password" binding:"required"`
74+ }
75+
76+ func (User ) ChangePassword () {
77+ saveLoginInfo , err := utils .GetLoginfo ()
78+ if err != nil {
79+ log .Println (err .Error ())
80+ return
81+ }
82+ fmt .Print ("Enter new password: " )
83+ bytepw , err := term .ReadPassword (int (syscall .Stdin ))
84+ if err != nil {
85+ os .Exit (1 )
86+ }
87+ pass := string (bytepw )
88+ fmt .Println ()
89+
90+ fmt .Print ("Again enter password: " )
91+ bytepw , err = term .ReadPassword (int (syscall .Stdin ))
92+ if err != nil {
93+ os .Exit (1 )
94+ }
95+ pass2 := string (bytepw )
96+ fmt .Println ()
97+
98+ if pass != pass2 {
99+ log .Panic ("Passwords are inconsistent!" )
100+ }
101+ passwordMd5 := utils .MD5 (pass )
102+
103+ checkBundleReq := changePasswordReq {
104+ Password : & passwordMd5 ,
105+ }
106+ Url , err := url .Parse (saveLoginInfo .ServerUrl + "/changePassword" )
107+ if err != nil {
108+ log .Panic ("server url error :" , err .Error ())
109+ }
110+
111+ jsonByte , _ := json .Marshal (checkBundleReq )
112+ reqStatus , err := utils .HttpPostToken [constants.RespStatus ](Url .String (), jsonByte , & saveLoginInfo .Token )
113+ if err != nil {
114+ fmt .Println (err )
115+ return
116+ }
117+ if reqStatus .Success {
118+ fmt .Println ("Change password success" )
119+ }
120+ }
121+
69122func (User ) Logout () {
70123 os .Remove ("./.code-push-go.json" )
71124 fmt .Println ("Logout success" )
0 commit comments