コード例 #1
0
ファイル: users.go プロジェクト: ovh/tat
// Me retrieves all information about me (exception information about Authentication)
func (*UsersController) Me(ctx *gin.Context) {
	var user = tat.User{}
	found, err := userDB.FindByUsername(&user, getCtxUsername(ctx))
	if !found {
		ctx.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
		return
	} else if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while fetching user"})
		return
	}
	gs, errGetGroupsOnlyName := groupDB.GetUserGroupsOnlyName(user.Username)
	if errGetGroupsOnlyName != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while getting groups"})
		return
	}
	user.Groups = gs
	out := &tat.UserJSON{User: user}
	ctx.JSON(http.StatusOK, out)
}