Skip to content

Commit 17efa62

Browse files
committed
Add change password
1 parent d6d00d7 commit 17efa62

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ chmod +x code-push-go
3131
#Update react native
3232
./code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <DeploymentName> -p <(*Optional) React native project default:./> --description <(*Optional) Description default: ""/> --hermes (*Optional)
3333

34+
#Change password
35+
./code-push-go change_password
36+
3437
#More command
3538
./code-push-go
3639
```

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ go 1.21.5
44

55
require github.com/aws/aws-sdk-go v1.51.22
66

7+
require (
8+
golang.org/x/sys v0.27.0 // indirect
9+
golang.org/x/term v0.26.0 // indirect
10+
)
11+
712
require (
813
github.com/google/uuid v1.6.0 // indirect
914
github.com/jmespath/go-jmespath v0.4.0 // indirect
1015
github.com/liushuochen/gotable v0.0.0-20221119160816-1113793e7092
16+
golang.org/x/crypto v0.29.0
1117
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ github.com/liushuochen/gotable v0.0.0-20221119160816-1113793e7092 h1:u9I3sJ+uTak
1010
github.com/liushuochen/gotable v0.0.0-20221119160816-1113793e7092/go.mod h1:CxUy8nDvutaC1pOfaG9TRoYwdHHqoNstSPPKhomC9k8=
1111
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1212
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13+
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
14+
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
15+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
16+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
17+
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
18+
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
1319
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1420
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func main() {
11-
fmt.Println("code-push-go V1.0.4")
11+
fmt.Println("code-push-go V1.0.5")
1212

1313
var args []string
1414
var notargs []string
@@ -30,7 +30,8 @@ func main() {
3030
" logout Log out of the current session\n" +
3131
" app View and manage your CodePush apps\n" +
3232
" create_bundle Create react native hotfix bundle\n" +
33-
" rollback Rollback last dundle"
33+
" rollback Rollback last dundle\n" +
34+
" change_password Change password"
3435

3536
var command string
3637
if len(args) <= 0 {
@@ -50,6 +51,8 @@ func main() {
5051
opt.App{}.App(args)
5152
case "rollback":
5253
opt.App{}.Rollback()
54+
case "change_password":
55+
opt.User{}.ChangePassword()
5356
default:
5457
fmt.Println(help)
5558
return

opt/user.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1517
type 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+
69122
func (User) Logout() {
70123
os.Remove("./.code-push-go.json")
71124
fmt.Println("Logout success")

0 commit comments

Comments
 (0)