chore: password can be empty when update me

refactor/fs
Noah Hsu 2022-07-23 20:49:16 +08:00
parent 4f3129ec28
commit 9d92834ee3
2 changed files with 6 additions and 4 deletions

View File

@ -18,7 +18,7 @@ var (
type LoginReq struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Password string `json:"password"`
}
func Login(c *gin.Context) {
@ -75,7 +75,9 @@ func UpdateCurrent(c *gin.Context) {
}
user := c.MustGet("user").(*model.User)
user.Username = req.Username
user.Password = req.Password
if req.Password != "" {
user.Password = req.Password
}
if err := db.UpdateUser(user); err != nil {
common.ErrorResp(c, err, 500)
} else {

View File

@ -22,8 +22,8 @@ func Init(r *gin.Engine) {
auth := api.Group("", middlewares.Auth)
api.POST("/auth/login", handles.Login)
auth.GET("/profile", handles.CurrentUser)
auth.POST("/profile/update", handles.UpdateCurrent)
auth.GET("/me", handles.CurrentUser)
auth.POST("/me/update", handles.UpdateCurrent)
// no need auth
public := api.Group("/public")