feat: change current user's profile

This commit is contained in:
Noah Hsu
2022-07-23 20:42:12 +08:00
parent fb65e98fa3
commit 4f3129ec28
3 changed files with 52 additions and 32 deletions

View File

@ -17,8 +17,8 @@ var (
)
type LoginReq struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
}
func Login(c *gin.Context) {
@ -66,3 +66,19 @@ func CurrentUser(c *gin.Context) {
userResp.Password = ""
common.SuccessResp(c, userResp)
}
func UpdateCurrent(c *gin.Context) {
var req LoginReq
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return
}
user := c.MustGet("user").(*model.User)
user.Username = req.Username
user.Password = req.Password
if err := db.UpdateUser(user); err != nil {
common.ErrorResp(c, err, 500)
} else {
common.SuccessResp(c)
}
}