File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Expand file tree Collapse file tree 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
103103- Password: admin
104104
105105### 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+ ```
107110
108111### Use [ code-push-go] ( https://github.com/htdcx/code-push-go )
109112``` shell
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import (
1313)
1414
1515func main () {
16- fmt .Println ("code-push-server-go V1.0.4 " )
16+ fmt .Println ("code-push-server-go V1.0.5 " )
1717 // gin.SetMode(gin.ReleaseMode)
1818 g := gin .Default ()
1919 g .Use (gzip .Gzip (gzip .DefaultCompression ))
@@ -42,6 +42,7 @@ func main() {
4242 authApi .GET ("/lsApp" , request.App {}.LsApp )
4343 authApi .POST ("/uploadBundle" , request.App {}.UploadBundle )
4444 authApi .POST ("/rollback" , request.App {}.Rollback )
45+ authApi .POST ("/changePassword" , request.User {}.ChangePassword )
4546 }
4647
4748 g .Run (configs .Port )
Original file line number Diff line number Diff line change @@ -5,3 +5,11 @@ type User struct {
55 UserName * string `gorm:"size:200" json:"userName"`
66 Password * string `gorm:"size:45" json:"-"`
77}
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 66
77 "com.lc.go.codepush/server/config"
88 "com.lc.go.codepush/server/model"
9+ "com.lc.go.codepush/server/model/constants"
910 "com.lc.go.codepush/server/utils"
1011 "github.com/gin-gonic/gin"
1112 "github.com/gin-gonic/gin/binding"
@@ -48,3 +49,23 @@ func (User) Login(ctx *gin.Context) {
4849 log .Panic (err .Error ())
4950 }
5051}
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