Last active
June 24, 2021 11:41
-
-
Save dipeshhkc/d650ebe0e125e70919428bf817d4bd85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AddUser - Register a user | |
func (h userController) AddUser(enforcer *casbin.Enforcer) gin.HandlerFunc { | |
return func(ctx *gin.Context) { | |
var user model.User | |
if err := ctx.ShouldBindJSON(&user); err != nil { | |
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | |
return | |
} | |
utils.HashPassword(&user.Password) | |
user, err := h.userRepo.AddUser(user) | |
if err != nil { | |
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | |
return | |
} | |
enforcer.AddGroupingPolicy(fmt.Sprint(user.ID), user.Role) | |
user.Password = "" | |
ctx.JSON(http.StatusOK, user) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment