feat: change current user's profile
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user