File tree 4 files changed +35
-2
lines changed 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,10 @@ chmod +x code-push-server-go
103
103
- Password: admin
104
104
105
105
### Change password and user name
106
- - Change mysql users tables (password need md5)
106
+ ``` shell
107
+ Version > = 1.0.5 :./code-push-go change_password
108
+ Version < = 1.0.4 :Change mysql users tables (password need md5)
109
+ ```
107
110
108
111
### Use [ code-push-go] ( https://github.com/htdcx/code-push-go )
109
112
``` shell
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import (
13
13
)
14
14
15
15
func main () {
16
- fmt .Println ("code-push-server-go V1.0.4 " )
16
+ fmt .Println ("code-push-server-go V1.0.5 " )
17
17
// gin.SetMode(gin.ReleaseMode)
18
18
g := gin .Default ()
19
19
g .Use (gzip .Gzip (gzip .DefaultCompression ))
@@ -42,6 +42,7 @@ func main() {
42
42
authApi .GET ("/lsApp" , request.App {}.LsApp )
43
43
authApi .POST ("/uploadBundle" , request.App {}.UploadBundle )
44
44
authApi .POST ("/rollback" , request.App {}.Rollback )
45
+ authApi .POST ("/changePassword" , request.User {}.ChangePassword )
45
46
}
46
47
47
48
g .Run (configs .Port )
Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ type User struct {
5
5
UserName * string `gorm:"size:200" json:"userName"`
6
6
Password * string `gorm:"size:45" json:"-"`
7
7
}
8
+
9
+ func (User ) TableName () string {
10
+ return "users"
11
+ }
12
+
13
+ func (User ) ChangePassword (uid int , password string ) error {
14
+ return userDb .Raw ("update users set password=? where id=?" , password , uid ).Scan (& User {}).Error
15
+ }
Original file line number Diff line number Diff line change 6
6
7
7
"com.lc.go.codepush/server/config"
8
8
"com.lc.go.codepush/server/model"
9
+ "com.lc.go.codepush/server/model/constants"
9
10
"com.lc.go.codepush/server/utils"
10
11
"github.com/gin-gonic/gin"
11
12
"github.com/gin-gonic/gin/binding"
@@ -48,3 +49,23 @@ func (User) Login(ctx *gin.Context) {
48
49
log .Panic (err .Error ())
49
50
}
50
51
}
52
+
53
+ type changePasswordReq struct {
54
+ Password * string `json:"password" binding:"required"`
55
+ }
56
+
57
+ func (User ) ChangePassword (ctx * gin.Context ) {
58
+ req := changePasswordReq {}
59
+ if err := ctx .ShouldBindBodyWith (& req , binding .JSON ); err == nil {
60
+ uid := ctx .MustGet (constants .GIN_USER_ID ).(int )
61
+ err := model.User {}.ChangePassword (uid , * req .Password )
62
+ if err != nil {
63
+ panic (err .Error ())
64
+ }
65
+ ctx .JSON (http .StatusOK , gin.H {
66
+ "success" : true ,
67
+ })
68
+ } else {
69
+ log .Panic (err .Error ())
70
+ }
71
+ }
You can’t perform that action at this time.
0 commit comments