Esempio n. 1
0
// @Title retrieveCurrentUser
// @Description Retrieve the current user.
// @Accept  json
// @Success 200 {object} model.User "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Liking is not deleted"
// @Resource /user
// @Router /user/current [get]
func retrieveCurrentUser(c *gin.Context) {
	user, status, err := userService.RetrieveCurrentUser(c)
	// if hasUser := log.CheckError(err); hasUser {
	if err == nil {
		c.JSON(status, gin.H{"hasAdmin": userPermission.HasAdmin(&user), "user": user})
	} else {
		c.JSON(200, gin.H{"hasAdmin": false, "user": nil})
	}

}
Esempio n. 2
0
// canUserWrite check that user can write an article.
func canUserWrite(c *gin.Context, category int) bool {
	canWrite := false
	user, err := userService.CurrentUser(c)
	if err == nil {
		if category == 100 {
			if userPermission.HasAdmin(&user) {
				canWrite = true
			}
		} else {
			canWrite = true
		}
	}
	return canWrite
}