// disable user func (u *User) Active(c *gin.Context) { if !isGranted(c, "user.active") { c.JSON(403, utils.NewNoAccessPermissionError("")) return } id := paramInt64(c, "id") var user models.User var data models.User if err := c.BindJSON(&data); err != nil { c.JSON(400, utils.NewInvalidJsonError()) return } if err := models.GetById(id, &user); err != nil { c.JSON(400, utils.NewNotFoundError()) return } fmt.Println("is active", data.IsActive) user.IsActive = data.IsActive if err := models.UpdateById(id, &user, "is_active"); err != nil { c.JSON(400, utils.NewError("update database failed - %s", err.Error())) return } c.JSON(200, gin.H{ "success": true, }) }
func currentUser(c *gin.Context) *models.User { sid, _ := c.Get("userid") if sid == "" { return nil } id, _ := strconv.ParseInt(fmt.Sprintf("%v", sid), 10, 64) var user models.User if err := models.GetById(id, &user); err != nil { fmt.Println("get user error:", err.Error()) return nil } return &user }
func (u *User) Get(c *gin.Context) { if !isGranted(c, "user.list") { c.JSON(403, utils.NewNoAccessPermissionError("")) return } id := paramInt64(c, "id") var user models.User if err := models.GetById(id, &user); err != nil { c.JSON(400, utils.NewNotFoundError()) return } c.JSON(200, user) }