(c *gin.Context)
| 241 | } |
| 242 | |
| 243 | func changeUserPassword(c *gin.Context) { |
| 244 | response := gin.H{"code": http.StatusOK} |
| 245 | defer c.JSON(http.StatusOK, response) |
| 246 | username, _ := c.GetPostForm("username") |
| 247 | password, _ := c.GetPostForm("password") |
| 248 | newPassword, _ := c.GetPostForm("new_password") |
| 249 | user := mydb.getUserProfile(username) |
| 250 | if user == nil { |
| 251 | response["code"] = http.StatusBadRequest |
| 252 | return |
| 253 | } |
| 254 | if user.Password != password { |
| 255 | response["code"] = http.StatusBadRequest |
| 256 | response["message"] = "password wrong" |
| 257 | return |
| 258 | } |
| 259 | user.Password = newPassword |
| 260 | if err := mydb.updateUserProfile(user); err != nil { |
| 261 | response["code"] = http.StatusInternalServerError |
| 262 | response["message"] = err.Error() |
| 263 | return |
| 264 | } |
| 265 | c.SetCookie("token", "", -1, "/", "", false, true) |
| 266 | } |
| 267 | |
| 268 | func Login(c *gin.Context) { |
| 269 | response := gin.H{"code": http.StatusOK} |
nothing calls this directly
no test coverage detected